jcs
/subtext
/amendments
/582
db: Terminate view buffer where FSRead reports it finished
On the odd chance that the file size reports one size and FSRead
reports reading less than that, we would have left garbage in the
buffer before terminating it. Now that FStat no longer includes the
resource fork size, this shouldn't happen, but better be safe.
jcs made amendment 582 10 months ago
--- db.c Tue Nov 28 11:25:42 2023
+++ db.c Wed Jan 24 09:07:37 2024
@@ -1009,18 +1009,21 @@ db_cache_views(struct db *tdb)
error = FSOpen(viewpath, 0, &frefnum);
if (error)
- panic("Error opening view %s: %d", PtoCstr(viewpath),
- error);
+ panic("Error opening view %s: %d", PtoCstr(viewpath), error);
size = sb.st_size;
error = FSRead(frefnum, &size, tdb->views[n]);
FSClose(frefnum);
- tdb->views[n][sb.st_size] = '\0';
-
if (error && error != eofErr)
panic("Error reading view %s: %d", PtoCstr(viewpath),
error);
+
+ if (size > sb.st_size)
+ panic("FSRead read more (%ld) than file size (%ld) for %s",
+ size, sb.st_size, PtoCstr(viewpath));
+
+ tdb->views[n][size] = '\0';
if (n == DB_VIEW_MENU_OPTIONS) {
opts = main_menu_parse(tdb->views[n], sb.st_size);