Fix #355: avoid undefined behaviour
Most instances relate to a left shift operation applied to a negative value. However, other issues were addressed such as reading uninitialized memory with non-boolean values, reading/writing past array bounds, numerical overflows, and bad pointer arithmetic.
Edited by Frank Bossen