Change buffer size checks to avoid the undefined overflow case.