The hack depends on numeric overflow in the caller that flips negative number into positive, so malloc can't possibly know it got the wrong size.
It's even funnier that signed overflow is Undefined Behavior in C, so the compiler is allowed to assume it can never happen (and thus let it happen, and even remove non-kosher overflow checks).
> The hack depends on numeric overflow in the caller that flips negative number into positive, so malloc can't possibly know it got the wrong size.
Look again at the hack-- Ted is sending a negative number to malloc. If I change malloc's interface to accept signed numbers, then I can check inside the definition for negative numbers and report to the user that something bad has happened.
It's even funnier that signed overflow is Undefined Behavior in C, so the compiler is allowed to assume it can never happen (and thus let it happen, and even remove non-kosher overflow checks).