Skip to content

Commit

Permalink
extmod/vfs_posix_file: Ensure file object has safe default fd.
Browse files Browse the repository at this point in the history
If file open fails the object will have fd = -1 (closed).

Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
Andrew Leech authored and andrewleech committed Feb 20, 2024
1 parent 223e0d9 commit a5393c1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions extmod/vfs_posix_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ STATIC void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_p

mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_obj_t mode_in) {
mp_obj_vfs_posix_file_t *o = m_new_obj_with_finaliser(mp_obj_vfs_posix_file_t);
o->fd = -1; // In case open() fails below, initialise this as a "closed" file object.
const char *mode_s = mp_obj_str_get_str(mode_in);

int mode_rw = 0, mode_x = 0;
Expand Down

0 comments on commit a5393c1

Please sign in to comment.