Misc fixes.

- Fix possible undefined behavior.
- Fix scram warning.