[PATCH 2/8] score: Fix allocation size calculation
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Sep 25 04:27:00 UTC 2020
On 24/09/2020 18:50, Gedare Bloom wrote:
>>> + /* Make sure the memory allocation size computation does not overflow */
>>> + if ( maximum_pending_messages > SIZE_MAX / buffer_size ) {
>> optimization: can we use mult instead?
>> if ( maximum_pending_messages * buffer_size > SIZE_MAX )
>> save a few cycles...
> Then again, maybe the division is needed here to ensure there isn't an
> overflow later? This stuff gets a little tricky!
>
I just used the code recommended by the SEI CERT C Coding Standard:
https://wiki.sei.cmu.edu/confluence/display/c/INT30-C.+Ensure+that+unsigned+integer+operations+do+not+wrap
More information about the devel
mailing list