Request Comments on an Overflow Coverage Case
Joel Sherrill
joel.sherrill at OARcorp.com
Tue Jul 5 19:17:55 UTC 2011
Hi,
I am looking at trying to deal with an
uncovered piece of code in coremsg.c (line 86)
http://www.rtems.org/ftp/pub/rtems/people/joel/coverage/erc32/erc32-Ospd-20110704-1327/annotated.html#range3
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
multiplication.
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.
From http://www.fefe.de/intof.html
int umult32(uint32 a,uint32 b,uint32* c) {
unsigned long long x=(unsigned long long)a*b;
if (x>0xffffffff) return 0;
*c=x&0xffffffff;
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 OARcorp.com 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