The compiler is able to warn you about this:
<source>:8:18: warning: comparison is always false due to limited range of data type [-Wtype-limits]
8 | if (*ptr == EOF) {
Of course this warning only happens when you target ARM, so I can imagine it's still hard to catch if you do all your development on x86, and only occasionally cross-compile to ARM without heeding compiler warnings.