Changeset d90fef2 in rtems


Ignore:
Timestamp:
Jul 8, 2011, 4:50:53 PM (8 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
4b68250
Parents:
06a36cd1
Message:

2011-07-08 Joel Sherrill <joel.sherrill@…>

  • score/src/coremsg.c: Use 64-bit intermediate result on multiply to reliably detect overflow.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r06a36cd1 rd90fef2  
     12011-07-08      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * score/src/coremsg.c: Use 64-bit intermediate result on multiply to
     4        reliably detect overflow.
     5
    162011-07-07      Joel Sherrill <joel.sherrill@oarcorp.com>
    27
  • cpukit/score/src/coremsg.c

    r06a36cd1 rd90fef2  
    3232
    3333/*
     34 *  size_t_mult32_with_overflow
     35 *
     36 *  This method multiplies two size_t 32-bit numbers and checks
     37 *  for overflow.  It returns false if an overflow occurred and
     38 *  the result is bad.
     39 */
     40static inline bool size_t_mult32_with_overflow(
     41  size_t  a,
     42  size_t  b,
     43  size_t *c
     44)
     45{
     46  long long x = (long long)a*b;
     47
     48  if ( x > SIZE_MAX )
     49    return false;
     50  *c = (size_t) x;
     51  return true;
     52}
     53
     54/*
    3455 *  _CORE_message_queue_Initialize
    3556 *
     
    5677)
    5778{
    58   size_t message_buffering_required;
     79  size_t message_buffering_required = 0;
    5980  size_t allocated_message_size;
    6081
     
    81102   *  check for overflow on the multiplication.
    82103   */
    83   message_buffering_required = (size_t) maximum_pending_messages *
    84        (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
    85 
    86   if (message_buffering_required < allocated_message_size)
     104  if ( !size_t_mult32_with_overflow(
     105        (size_t) maximum_pending_messages,
     106        allocated_message_size + sizeof(CORE_message_queue_Buffer_control),
     107        &message_buffering_required ) )
    87108    return false;
    88109
Note: See TracChangeset for help on using the changeset viewer.