Assorted fixes for -fsanitize=undefined

Adam Jackson requested to merge ajax/xserver:ubsan-fixes into master

This doesn't fix everything needed to enable sanitize builds in CI, but it's a start.

Merge request reports