Import Ruby r47996

* Avoid undefined behaviors found by gcc -fsanitize=undefined.
  gcc (Debian 4.9.1-16) 4.9.1
Fix indents