
<                                 cp += es;
---
>                                 cp += es;
>                                 if (cp >= tf_buf + tf_bytesperrow) {
>                                     break;  // Exit loop if we've reached the end of the buffer
>                                 }
