notcurses
notcurses copied to clipboard
use better overflow check
This is a better mergable #2767, but my fork got out of sync and there were superflous commits in there. Sorry for the inconvenience. Here's my original comment.
I think you will like this much better. The other code was more or less a mitigation but this should be a better overflow checker. The multiplication does the zero check and the comparison checks that the multiplication doesn't overflow. calloc will then do the other overflow check.
Adding to this: The old code caught overflow with large negative numbers, but this one will catch any kind of overflow. Also the code is easier to understand IMO.