[PATCH 10/12] satcan.c: Fix Unsigned compared against 0 (CID #1399768)

Gedare Bloom gedare at rtems.org
Fri Mar 5 15:15:10 UTC 2021


On Fri, Mar 5, 2021 at 8:13 AM Joel Sherrill <joel at rtems.org> wrote:
>
>
>
> On Fri, Mar 5, 2021, 9:08 AM Gedare Bloom <gedare at rtems.org> wrote:
>>
>> On Thu, Mar 4, 2021 at 12:50 PM Ryan Long <thisisryanlong at gmail.com> wrote:
>> >
>> > CID 1399768: Unsigned compared against 0 in satcan_ioctl().
>> >
>> > Closes #4294
>> > ---
>> >  bsps/shared/grlib/can/satcan.c | 16 ++++------------
>> >  1 file changed, 4 insertions(+), 12 deletions(-)
>> >
>> > diff --git a/bsps/shared/grlib/can/satcan.c b/bsps/shared/grlib/can/satcan.c
>> > index c3fdc15..52e674c 100644
>> > --- a/bsps/shared/grlib/can/satcan.c
>> > +++ b/bsps/shared/grlib/can/satcan.c
>> > @@ -239,9 +239,7 @@ static rtems_device_driver satcan_ioctl(rtems_device_major_number major, rtems_d
>> >                 /* Get regmod structure from argument */
>> >                 regmod = (satcan_regmod*)ioarg->buffer;
>> >                 DBG("SatCAN: ioctl: getting register %d\n\r", regmod->reg);
>> should these DBG prints also be changed to %u?
>
>
> Probably. Can this be put on his todo list? Enable the debug prints in grlib and see what printf format specifier warnings come out?
>
> This would seem to be the most reliable way to catch them all.

Yes, I'm ok with the various grlib patches, but make notes to
follow-up on this and perhaps the question whether one can call
brm_write() with rw_args->count = 0, and if so what the behavior
should be.

>>
>>
>> > -               if (regmod->reg < 0)
>> > -                       return RTEMS_INVALID_NAME;
>> > -               else if (regmod->reg <= SATCAN_FILTER_STOP)
>> > +               if (regmod->reg <= SATCAN_FILTER_STOP)
>> >                         regmod->val = regs->satcan[regmod->reg];
>> >                 else if (regmod->reg == SATCAN_WCTRL)
>> >                         regmod->val = regs->ctrl;
>> > @@ -260,9 +258,7 @@ static rtems_device_driver satcan_ioctl(rtems_device_major_number major, rtems_d
>> >                 regmod = (satcan_regmod*)ioarg->buffer;
>> >                 DBG("SatCAN: ioctl: setting register %d, value %x\n\r",
>> >                     regmod->reg, regmod->val);
>> > -               if (regmod->reg < 0)
>> > -                       return RTEMS_INVALID_NAME;
>> > -               else if (regmod->reg <= SATCAN_FILTER_STOP)
>> > +               if (regmod->reg <= SATCAN_FILTER_STOP)
>> >                         regs->satcan[regmod->reg] = regmod->val;
>> >                 else if (regmod->reg == SATCAN_WCTRL)
>> >                         regs->ctrl = regmod->val;
>> > @@ -281,9 +277,7 @@ static rtems_device_driver satcan_ioctl(rtems_device_major_number major, rtems_d
>> >                 regmod = (satcan_regmod*)ioarg->buffer;
>> >                 DBG("SatCAN: ioctl: or:ing register %d, with value %x\n\r",
>> >                     regmod->reg, regmod->val);
>> > -               if (regmod->reg < 0)
>> > -                       return RTEMS_INVALID_NAME;
>> > -               else if (regmod->reg <= SATCAN_FILTER_STOP)
>> > +               if (regmod->reg <= SATCAN_FILTER_STOP)
>> >                         regs->satcan[regmod->reg] |= regmod->val;
>> >                 else if (regmod->reg == SATCAN_WCTRL)
>> >                         regs->ctrl |= regmod->val;
>> > @@ -302,9 +296,7 @@ static rtems_device_driver satcan_ioctl(rtems_device_major_number major, rtems_d
>> >                 regmod = (satcan_regmod*)ioarg->buffer;
>> >                 DBG("SatCAN: ioctl: masking register %d, with value %x\n\r",
>> >                     regmod->reg, regmod->val);
>> > -               if (regmod->reg < 0)
>> > -                       return RTEMS_INVALID_NAME;
>> > -               else if (regmod->reg <= SATCAN_FILTER_STOP)
>> > +               if (regmod->reg <= SATCAN_FILTER_STOP)
>> >                         regs->satcan[regmod->reg] &= regmod->val;
>> >                 else if (regmod->reg == SATCAN_WCTRL)
>> >                         regs->ctrl &= regmod->val;
>> > --
>> > 1.8.3.1
>> >
>> > _______________________________________________
>> > devel mailing list
>> > devel at rtems.org
>> > http://lists.rtems.org/mailman/listinfo/devel
>> _______________________________________________
>> devel mailing list
>> devel at rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel


More information about the devel mailing list