Skip to content

Commit 7cad746

Browse files
committed
sd: use right types for length_out
The out length param defined in f_read is of type UINT (typedef of unsigned int). The sd_load_bin function uses size_t for the out length param. On the BitBox02 they are both 4 bytes so it works out. On x86, size_t is 8 bytes while unsigned int is only 4 bytes, which leads to a corrupt value due to the invalid cast.
1 parent eb80872 commit 7cad746

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/sd.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ bool sd_load_bin(const char* fn, const char* dir, uint8_t* buffer, size_t* lengt
269269
_unmount();
270270
return false;
271271
}
272-
FRESULT result = f_read(&file_object, buffer, f_size(&file_object), (unsigned int*)length_out);
272+
UINT len = 0;
273+
FRESULT result = f_read(&file_object, buffer, f_size(&file_object), &len);
274+
// UINT and size_t can have different sizes but both are at least 4 bytes.
275+
*length_out = (size_t)len;
273276
f_close(&file_object);
274277
_unmount();
275278
return result == FR_OK;

0 commit comments

Comments
 (0)