dankamongmen / notcurses

blingful character graphics/TUI library. definitely not curses.
https://nick-black.com/dankwiki/index.php/Notcurses
Other
3.4k stars 113 forks source link

use better overflow check #2768

Open mulle-nat opened 4 months ago

mulle-nat commented 4 months ago

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.

dankamongmen commented 4 months ago

if we're really committing to this catch overflow idea, don't we want it backing ncplane_create(), and thus handling all ncplane creations?

dankamongmen commented 4 months ago

if we're really committing to this catch overflow idea, don't we want it backing ncplane_create(), and thus handling all ncplane creations?

nevermind, i think it is by virtue of being in ncplane_new_internal()

mulle-nat commented 4 months ago

Just wondering, if I need to add some more comments here, or if everything is clear.