[PATCH] Replace int -> uint to avoid signed integer overflow

Kang-Che Sung explorer09 at gmail.com
Mon Feb 6 11:05:54 UTC 2017


In case that Rob Landley isn't convinced, there is another argument
supporting casting to unsigned before bit shifting:

There are little cases that left shifting to sign bit is actually useful.
AFAIK, the use of 1<<31 cases are no other than
1. intended to represent a signed INTn_MIN constant,
2. intended to do arithmetic (signed) left shift, without checking
overflow (a bad coding practice and potential bug),
3. doing shift on a bitfield or unsigned int but forgot to cast it to
unsigned.

It seems to me that this bunzip2 case is case 3, and for readability
I support changing the variable types to unsigned where they
should be.


More information about the busybox mailing list