File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,13 +93,15 @@ bool RegionMap::load(FILESYSTEM* _fs, const char* path) {
9393 while (num_regions < MAX_REGION_ENTRIES ) {
9494 auto r = ®ions[num_regions];
9595
96- success = file.read ((uint8_t *) &r->id , sizeof (r->id )) == sizeof (r->id );
96+ int n = file.read ((uint8_t *) &r->id , sizeof (r->id ));
97+ if (n == 0 ) break ; // clean EOF
98+ success = (n == sizeof (r->id ));
9799 success = success && file.read ((uint8_t *) &r->parent , sizeof (r->parent )) == sizeof (r->parent );
98100 success = success && file.read ((uint8_t *) r->name , sizeof (r->name )) == sizeof (r->name );
99101 success = success && file.read ((uint8_t *) &r->flags , sizeof (r->flags )) == sizeof (r->flags );
100102 success = success && file.read (pad, sizeof (pad)) == sizeof (pad);
101103
102- if (!success) break ; // EOF
104+ if (!success) break ; // partial read or corruption
103105
104106 if (r->id >= next_id) { // make sure next_id is valid
105107 next_id = r->id + 1 ;
@@ -108,7 +110,7 @@ bool RegionMap::load(FILESYSTEM* _fs, const char* path) {
108110 }
109111 }
110112 file.close ();
111- return true ;
113+ return success ;
112114 }
113115 }
114116 return false ; // failed
You can’t perform that action at this time.
0 commit comments