4 ms·
Maybe it's late but I don't get it. Can someone spell it out for me?
by AceJohnny2 4y ago
Maybe it's late but I don't get it. Can someone spell it out for me?
- wruza 4y agoIf n != 0 and -1 cast to unsigned size_t divided by n is less than m. So that m times n would be bigger than size_t’s maximum value. Edit: inverted meaning since check is for error, not for ok case.
- dannymi 4y agoYou 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.