gcc warns about possible string non-termination after `strncpy()`
claudeha opened this issue · comments
Claude Heiland-Allen commented
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-truncation suggests using memcpy()
instead if NUL termination is not required, if NUL is needed buffer should be bigger or size to copy should be smaller (and maybe the final NUL needs to be added manually). Haven't investigated further to know which is the case...
../../imgui-filebrowser/imfilebrowser.h: In member function ‘void ImGui::FileBrowser::Display()’:
../../imgui-filebrowser/imfilebrowser.h:475:41: warning: ‘char* strncpy(char*, const char*, size_t)’ specified bound 512 equals destination size [-Wstringop-truncation]
475 | std::strncpy(inputNameBuf_->data(),
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
476 | u8StrToStr(rsc.name.u8string()).c_str(),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
477 | inputNameBuf_->size());
| ~~~~~~~~~~~~~~~~~~~~~~
imgui-filebrowser/imfilebrowser.h
Lines 475 to 477 in d9bec46
Z Guan commented
Tks for reporting this! have fixed this in the newest version.