Avoid undefined behaviour in libc

re: comment on 21154dec190bcbd017040d050dbf1ff38d9ef9ae