AirGuanZ / imgui-filebrowser

File browser implementation for dear-imgui. C++17 is required.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gcc warns about possible string non-termination after `strncpy()`

claudeha opened this issue · comments

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());
      |                                          ~~~~~~~~~~~~~~~~~~~~~~

std::strncpy(inputNameBuf_->data(),
u8StrToStr(rsc.name.u8string()).c_str(),
inputNameBuf_->size());

Tks for reporting this! have fixed this in the newest version.