Fix compiler warnings spotted by Jonatan Lindblad.

Cherry-picked from most of c06c191712a7e0721a423528f37420c30d53cab7.