You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While compiling the current master branch (eb6dcab) there's the following warning (which I didn't notice when I submitted the previous warning fix at #3686 because I had SUPPORT_FILEFORMAT_GIF disabled at the time):
In file included from rtextures.c:64:
rtextures.c: In function ‘LoadImageAnimFromMemory’:
rtextures.c:463:21: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
463 | RL_FREE(fileData);
| ^~~~~~~~
raylib.h:136:38: note: in definition of macro ‘RL_FREE’
136 | #define RL_FREE(ptr) free(ptr)
| ^~~
In file included from rtextures.c:76:
/usr/include/stdlib.h:555:25: note: expected ‘void *’ but argument is of type ‘const unsigned char *’
555 | extern void free (void *__ptr) __THROW;
| ~~~~~~^~~~~
Proposed solution
I see two ways to fix this:
A. Removing const (L446, L1305) from the fileData parameter and leaving the RL_FREE(fileData); (L463) there.
B. Or leaving the const (L446, L1305) there and removing the RL_FREE(fileData); (L463).
I think B would be the better approach, leaving to the user to free his fileData when he no longer needs it. As it's right now, it assumes the file data should be freed regarless, which is not the case on the similar LoadImageFromMemory() (L482).
@ubkp Oh! Good catch! Thanks for reporting! That function was added very recently and I didn't notice this issue!
Indeed, the RL_FREE(fileData) shouldn't be there! When dealing with memory data passed to the function, the caller is the owner of that data, the function should not touch it!
Issue description
While compiling the current master branch (eb6dcab) there's the following warning (which I didn't notice when I submitted the previous warning fix at #3686 because I had
SUPPORT_FILEFORMAT_GIF
disabled at the time):Proposed solution
I see two ways to fix this:
A. Removing
const
(L446, L1305) from thefileData
parameter and leaving theRL_FREE(fileData);
(L463) there.B. Or leaving the
const
(L446, L1305) there and removing theRL_FREE(fileData);
(L463).I think B would be the better approach, leaving to the user to free his
fileData
when he no longer needs it. As it's right now, it assumes the file data should be freed regarless, which is not the case on the similarLoadImageFromMemory()
(L482).@raysan5 Which's your prefered approach?
References
LoadImageAnimFromMemory()
warning forfileData
#3686Environment
PLATFORM_DESKTOP
,Linux
(Mint 21.1 64-bit).Code Example
The text was updated successfully, but these errors were encountered: