
< while (buf[len - 1] == 0x20) len--;
---
> for (; len > 0 && buf[len - 1] == 0x20; len--);
