4 ms·
You want to evaluate p in: p = m n If that is gonna overflow, p > SIZE_MAX. Then it would be that (by substitution) m n > SIZE_MAX so m > SIZE_MAX/n
by dannymi 4y ago
You want to evaluate p in:
p = m n
If that is gonna overflow, p > SIZE_MAX.
Then it would be that (by substitution)
m n > SIZE_MAX
so
m > SIZE_MAX/n
except if n = 0. In the latter case, m can be as big as it wants--p will always evaluate to 0.
And (size_t)-1 is a silly way to write SIZE_MAX (but it saves you a dependency).
- AceJohnny2 4y agoThanks! Indeed the `(size_t)-1` threw me off, and the `m && n` was an interesting obfuscation for checking whether either are 0.