Skip to content

Commit e658042

Browse files
Fix segfault in filehandling due to incorrect use of signed vs unsigned int (#726)
This fixes bugs introduced in d905976
1 parent 018d5f4 commit e658042

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/misc/fgets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#if ! defined(EMULATOR) || EMULATOR == USE_INTERNAL_FS
2020

2121
#define FILE void
22-
uintptr_t _open_r(void *r, const char *file, int flags, int mode);
22+
intptr_t _open_r(void *r, const char *file, int flags, int mode);
2323
int _close_r(void *r);
2424
int _read_r(void *r, char * ptr, int len);
2525
int _write_r(void *r, char * ptr, int len);
@@ -32,7 +32,7 @@ FILE *devo_fopen2(void *r, const char *path, const char *mode)
3232
int flags = (mode && *mode == 'w') ? O_CREAT : 0;
3333
int _mode = flags ? O_WRONLY : O_RDONLY;
3434

35-
uintptr_t fd = _open_r(r, path, flags, _mode);
35+
intptr_t fd = _open_r(r, path, flags, _mode);
3636
if (fd <= 0)
3737
return NULL;
3838
return (FILE *)fd;

src/target/drivers/filesystems/syscalls.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern void init_err_handler();
4747
int FS_Mount();
4848
void FS_Unmount();
4949

50-
uintptr_t _open_r(FIL *r, const char *file, int flags, int mode);
50+
intptr_t _open_r(FIL *r, const char *file, int flags, int mode);
5151
int _close_r(FIL *r);
5252

5353

@@ -127,7 +127,7 @@ void FS_CloseDir()
127127
{
128128
}
129129

130-
uintptr_t _open_r(FIL *r, const char *file, int flags, int mode) {
130+
intptr_t _open_r(FIL *r, const char *file, int flags, int mode) {
131131
(void)flags;
132132
(void)mode;
133133

@@ -204,7 +204,7 @@ int _write_r(FIL *r, char * ptr, int len)
204204

205205
int _ltell_r(FIL *r)
206206
{
207-
if ((uintptr_t)r > 2 && fs_is_open(r)) {
207+
if ((intptr_t)r > 2 && fs_is_open(r)) {
208208
return (int)fs_ltell(r);
209209
}
210210
return -1;
@@ -214,7 +214,7 @@ int _lseek_r(FIL *r, int ptr, int dir)
214214
{
215215
(void)r;
216216

217-
if ((uintptr_t)r > 2 && fs_is_open(r)) {
217+
if ((intptr_t)r > 2 && fs_is_open(r)) {
218218
if (dir == SEEK_CUR) {
219219
ptr += fs_ltell(r);
220220
} else if (dir == SEEK_END) {

0 commit comments

Comments
 (0)