AP_Filesystem: correct fgets for last-line-missing-termination

refusal to seek past the end of the file broke this
This commit is contained in:
Peter Barker
2026-07-21 18:56:09 +10:00
committed by Peter Barker
parent 04283d5155
commit ad28bb78d2
+7 -2
View File
@@ -365,8 +365,13 @@ bool AP_Filesystem::fgets(char *buf, uint8_t buflen, int fd)
}
buf[i] = '\0';
// get back to the right offset
if (backend.fs.lseek(fd, offset_start+i+1, SEEK_SET) != offset_start+i+1) {
// get back to the right offset, consuming the line terminator if
// we found one. If we did not find one we have either filled the
// buffer or returned an unterminated final line; in both cases
// the seek target must not extend past the data we consumed -
// backends such as ROMFS refuse to seek past the end of the file.
const int32_t new_offset = offset_start + i + (i < n ? 1 : 0);
if (backend.fs.lseek(fd, new_offset, SEEK_SET) != new_offset) {
// we need to fail if we can't seek back or the caller may loop or get corrupt data
return false;
}