
<     if (frame_end - frame < width + 3)
---
>     if (frame_end - frame < width + 3)
>         return -1; // Or an appropriate error code
