Skip to content

Commit e08cc50

Browse files
cfriedthenrikbrixandersen
authored andcommitted
os: fdtable: set offset to zero with newly reserved fd's
Previously, if a file object is was re-used, it could inherit the offset field of the previously closed file object, making reading from the beginning of the file impossible until the offset was manually zero'ed. The offset should *always* be zero when a file is ready to be used. The issue really only presents itself when implementing a vtable backend. Signed-off-by: Chris Friedt <[email protected]>
1 parent 2a2806b commit e08cc50

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/os/fdtable.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ int zvfs_reserve_fd(void)
249249
(void)z_fd_ref(fd);
250250
fdtable[fd].obj = NULL;
251251
fdtable[fd].vtable = NULL;
252+
fdtable[fd].offset = 0;
252253
k_mutex_init(&fdtable[fd].lock);
253254
k_condvar_init(&fdtable[fd].cond);
254255
}

0 commit comments

Comments
 (0)