6 ms·
>"31-bit" is not a typo - PNG defines a "PNG four byte integer", which is limited to the range 0 to 231-1, to defend against the existence of C programmers. Wh
by Cloudef 4y ago
>"31-bit" is not a typo - PNG defines a "PNG four byte integer", which is limited to the range 0 to 231-1, to defend against the existence of C programmers.
What exactly is implied here? Silly guard against overflow?
- edflsafoiewq 4y agoIt's "in order to accommodate languages that have difficulty with unsigned four-byte values" ie. Java.
- Cloudef 4y agoThat makes more sense
- Retr0id 4y agoMostly just a joke at C's expense. When reviewing C code, any time the sign-bit gets touched I consider the danger zone to have been entered (especially in the context of parsing data). Limiting the range of ints is a good defensive programming tactic. As another commenter points out, the real reason is about practicality - some languages like Java don't natively support unsigned ints.
- Cloudef 4y agoMaybe I'm old, but i dont get it. I'd say signed is more dangerous as the overflow is undefined. And if you read to unsigned, you are just wasting range.
- Retr0id 4y agoYes, that's the point. Signed ints are a potential footgun, which can be partially mitigated by limiting the range to 0 - 2^31-1. Good specs pre-emptively mitigate implementation bugs.
- deleted 4y ago[deleted]
- roel_v 4y agoYeah I found that part a bit opaque as well. What about alignment? Does it just use 4 byte integers but one bit is unused? Isn't that a much more clear way of putting it?