Ah! Okay this works every time!
Well Done and Thank You
By the way, why is this?
Ah! Okay this works every time!
Well Done and Thank You
By the way, why is this?
(cc @kisvegabor)
It looks like there was a mixup between the open
and fopen
functions.
TL;DR open
will return -1
if opening the file failed, while fopen
will return NULL
. However, the failure check seems to have mixed them up.
The reason you got away with this in rare cases is because of the cast to a signed integer. Let’s assume for our purposes that all pointers and integers are 32-bit.
Under normal conditions, fopen
will return a pointer to a stream. The maximum signed 32-bit integer is 0x7FFFFFFF
. Let’s say that fopen
returned a pointer that was greater than that value (e.g. 0x80000000
).
If the value 0x80000000
were to be forced into a 32-bit signed integer, it would equal the smallest possible signed integer (roughly negative two billion). Since that is a negative number, the check would fail even though the file was opened successfully.
In the meantime, I’ve fixed the issue here: Fix incorrect failure check in pcfs_open · lvgl/lv_demos@2b3c400 · GitHub
Thank you for finding it! I am still surprised that no other implementations of fopen
have ever caused this issue.
Wow, nice catch!
Thank you for the fix!