Request Comments on an Overflow Coverage Case

Joel Sherrill joel.sherrill at
Tue Jul 5 19:17:55 UTC 2011


I am looking at trying to deal with an
uncovered piece of code in coremsg.c (line 86)

This is trying to detect overflow when
determining the amount of memory to allocate
for the buffers.  As best I can tell, it
misses a lot of overflow cases for the following

needed = num msgs * size of a msg

Looking around on the web for suggestions, it
looks like the most reliable technique is
to do a 32x32 multiply into a 64-bit result.
Then see if the answer is too large for 32 bits.

int umult32(uint32 a,uint32 b,uint32* c) {
   unsigned long long x=(unsigned long long)a*b;
   if (x>0xffffffff) return 0;
   return 1;

Since this is only an issue during object
creation, I think using this technique
via a helper routine like the above would
make sense.

Any thoughts? suggestions?

Joel Sherrill, Ph.D.             Director of Research&  Development
joel.sherrill at        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
    Support Available             (256) 722-9985

More information about the users mailing list