[PATCH 04/20] libchip/serial/ns16550* and z8530*: Assert on baud number to avoid divide by 0
Chris Johns
chrisj at rtems.org
Wed Nov 26 07:36:56 UTC 2014
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.
Chris
More information about the devel
mailing list