Fixes to clean undefined behavior (see ROOT-6710) detected by running all the tests and tutorials with gcc4.9.0 and -fsanitize=undefined