Changeset 02958c5e in rtems


Ignore:
Timestamp:
Nov 19, 2014, 8:28:08 PM (5 years ago)
Author:
Josh Oguin <josh.oguin@…>
Branches:
4.11, master
Children:
aed6e1d
Parents:
0ad1e80
git-author:
Josh Oguin <josh.oguin@…> (11/19/14 20:28:08)
git-committer:
Joel Sherrill <joel.sherrill@…> (11/26/14 13:51:57)
Message:

libchip/serial/ns16550* and z8530*: Assert on baud number to avoid divide by 0

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.

Location:
c/src/libchip/serial
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/libchip/serial/ns16550-context.c

    r0ad1e80 r02958c5e  
    593593  /*
    594594   *  Calculate the baud rate divisor
     595   *
     596   *  Assert ensures there is no division by 0.
    595597   */
    596598
    597599  baud_requested = rtems_termios_baud_to_number(t->c_cflag);
     600  _Assert( baud_requested != 0 );
     601
    598602  ulBaudDivisor = NS16550_GetBaudDivisor(ctx, baud_requested);
    599603
  • c/src/libchip/serial/ns16550.c

    r0ad1e80 r02958c5e  
    533533  /*
    534534   *  Calculate the baud rate divisor
     535   *
     536   *  Assert ensures there is no division by 0.
    535537   */
    536538
    537539  baud_requested = rtems_termios_baud_to_number(t->c_cflag);
     540  _Assert( baud_requested != 0 );
    538541  ulBaudDivisor = NS16550_GetBaudDivisor(c, baud_requested);
    539542
  • c/src/libchip/serial/z85c30.c

    r0ad1e80 r02958c5e  
    438438  uint32_t               wr5;
    439439  int                    baud_requested;
     440  uint32_t               baud_number;
    440441  setRegister_f          setReg;
    441442  rtems_interrupt_level  Irql;
     
    446447  /*
    447448   *  Calculate the baud rate divisor
     449   *
     450   *  Assert ensures there is no division by 0.
    448451   */
    449452
     
    452455    baud_requested = B9600;              /* default to 9600 baud */
    453456
     457  baud_number = (uint32_t) rtems_termios_baud_to_number( baud_requested );
     458  _Assert( baud_number != 0 );
     459
    454460  ulBaudDivisor = Z85C30_Baud(
    455461    (uint32_t) Console_Port_Tbl[minor]->ulClock,
    456     (uint32_t) rtems_termios_baud_to_number( baud_requested )
     462    baud_number
    457463  );
    458464
Note: See TracChangeset for help on using the changeset viewer.