3 ms·
> if (n && m > (size_t)-1/n) Shouldn't the case of wraparound be caught by testing the resulting size as following? s = n*m; if (n && s >= n && s >= m) /*
by zoomablemind 4y ago
> if (n && m > (size_t)-1/n)
Shouldn't the case of wraparound be caught by testing the resulting size as following?
s = n*m;
if (n && s >= n && s >= m) /* no overflow */ ...
- CUViper 4y agoThat doesn't work for multiplication -- e.g. in 8-bit, 20 * 20 wraps to 144.