Fix several warnings and bugs on unusual platforms