Avoid undefined shift behaviour

Pointed out by @gmaxwell.