News for hackers. Stuff that matters.
Re:Why Does Calloc Exist? by dannymi on Sunday November 13, 2022 @08:44AM (#33582989)
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).

Re:Why Does Calloc Exist? by AceJohnny2 on Sunday November 13, 2022 @08:19PM (#33589194)
Thanks! Indeed the `(size_t)-1` threw me off, and the `m && n` was an interesting obfuscation for checking whether either are 0.