[PATCH 04/20] libchip/serial/ns16550* and z8530*: Assert on baud number to avoid divide by 0

Gedare Bloom gedare at rtems.org
Wed Nov 26 15:33:57 UTC 2014


On Wed, Nov 26, 2014 at 2:36 AM, Chris Johns <chrisj at rtems.org> wrote:
>
> On 26/11/2014 10:02 am, Joel Sherrill wrote:
>>
>> From: Josh Oguin <josh.oguin at oarcorp.com>
>>
>> This was flagged by CodeSonar. It should be impossible to get an
>> incorrect baud number back but ensure this in debug mode. The _Assert()
>> keeps their scanner from evaluating for divide by 0 past this point.
>> ---
>>   c/src/libchip/serial/ns16550-context.c | 4 ++++
>>   c/src/libchip/serial/ns16550.c         | 3 +++
>>   c/src/libchip/serial/z85c30.c          | 8 +++++++-
>>   3 files changed, 14 insertions(+), 1 deletion(-)
>>
>> diff --git a/c/src/libchip/serial/ns16550-context.c
>> b/c/src/libchip/serial/ns16550-context.c
>> index 00ad89c..087627a 100644
>> --- a/c/src/libchip/serial/ns16550-context.c
>> +++ b/c/src/libchip/serial/ns16550-context.c
>> @@ -592,9 +592,13 @@ static bool ns16550_set_attributes(
>>
>>     /*
>>      *  Calculate the baud rate divisor
>> +   *
>> +   *  Assert ensures there is no division by 0.
>>      */
>>
>>     baud_requested = rtems_termios_baud_to_number(t->c_cflag);
>> +  _Assert( baud_requested != 0 );
>> +
>
>
> Should this return an error or the value should be tested in an upper layer.
> I will raise a ticket to have the upper layers reject B0 as a baud rate.
>
Good point.

> Chris
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel



More information about the devel mailing list