> Try writing C functions add, subtract, multiply, and divide, that do anything on overflow except UB.
For those curious...
https://www.securecoding.cert.org/confluence/display/c/INT32...
Re:Should I Use Signed or Unsigned Ints?
by revelation on Saturday August 01, 2015 @06:40PM
(#9988990)
Well, there are builtin functions that do this safely for signed integers.
Of course that means you need to be aware which calculations are potentially dangerous, you need to know about signed integer overflow problems in the first place, etc. ..
Re:Should I Use Signed or Unsigned Ints?
by michaelhoffman on Saturday August 01, 2015 @11:23PM
(#9989616)
What functions are those?
A key difference is whether the type is meant to be an index (counting) or for arithmetic. Indexing with unsigned integers certainly has its pitfalls:
But this is outweighed by the enormous and under-appreciated dangers of signed arithmetic!Try writing C functions add, subtract, multiply, and divide, that do anything on overflow except UB. It's trivial with unsigned, but wretched and horrible with signed types. And real software like PostgreSQL gets it wrong, with crashy consequences: http://kqueue.org/blog/2012/12/31/idiv-dos/#sql