This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework file browser to quiet spurious gcc-14 string warning
gcc-14 warns: ``` similar/main/menu.cpp: In member function 'virtual dcx::window_event_result dcx::{anonymous}::browser::callback_handler(const dcx::d_event&, dcx::window_event_result)': similar/main/menu.cpp:2349:86: error: '%s' directive output may be truncated writing up to 4095 bytes into a region of size between 1 and 4096 [-Werror=format-truncation=] 2349 | snprintf(&newpath[len_newpath], newpath.size() - len_newpath, "%s%s", (len_newpath >= len_sep && strncmp(&newpath[len_newpath - len_sep], sep, len_sep)) ? sep : "", list[citem]); | ^~ ``` This is because it assumes printing `sep` could consume the entire buffer, leaving no space for `list[citem]`. It can be silenced by using `%.*s` for both strings, and setting the length limit equal to `strlen(that_string)`, which is an expensive way of writing the same expression. `snprintf` will already stop at the null terminator, so the length limit does not constrain it further. The warning might be explained if the compiler assumes that the strings became longer after they were first measured, but such a change cannot happen in this program. Avoid the whole problem by replacing the `snprintf` with a pair of `std::ranges::copy_n` calls, which implementations should be able to convert to `memcpy`.
- Loading branch information