cfgfile_option() returns address from a local buffer
broadblues opened this issue · 3 comments
broadblues commented
Saw the following warning whilst building latest amiberry
src/cfgfile.cpp:497:1: warning: function may return address of local variable [-Wreturn-local-addr]
497 | }
| ^
src/cfgfile.cpp:466:15: note: declared here
466 | TCHAR buf[MAX_DPATH];
| ^~~
src/cfgfile.cpp: In function âTCHAR* cfgfile_option_find_it(const TCHAR*, const TCHAR*, bool)â:
src/cfgfile.cpp:497:1: warning: function may return address of local variable [-Wreturn-local-addr]
497 | }
| ^
src/cfgfile.cpp:466:15: note: declared here
466 | TCHAR buf[MAX_DPATH];
| ^~~
Checking the code it does seem that a pointer to the contents of "buf" are returned.
Fix might be a simple as declaring it static
ie
static TCHAR buf[MAX_DPATH];
Depends on if it needs to be threadsafe.
midwan commented
@broadblues
Thanks!
This is actually the same upstream as well (WinUAE), so I'll send a PR to Toni and ask about it.
midwan commented
Reported upstream here: tonioni/WinUAE#263