From bfffd37e1f804ca4fae1caae106935791696b6a9 Mon Sep 17 00:00:00 2001 From: Philip Top Date: Mon, 27 Oct 2025 06:17:19 -0700 Subject: [PATCH] code simplification (#1244) Based on #1242, I don't think this is required but it does remove that issue and checking on compiler explore it does simplify the generated code. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ include/CLI/StringTools.hpp | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91d8f0a7..985cce23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,11 @@ and a potential segmentation fault from specially crafted config files - Fixed incorrect inclusion of definition for extra validators [#1238][] - Fixed fuzz generated failure from crafted files introduced in recent release [#1238][] +- Removed some usage of static const std::string in inline function that had + potential memory issues when CLI11 is used with shared libraries, this likely + isn't a bug but the fix did result in smaller code size so was kept. [#1244][] +[#1244]: https://github.com/CLIUtils/CLI11/pull/1244 [#1238]: https://github.com/CLIUtils/CLI11/pull/1238 [#1239]: https://github.com/CLIUtils/CLI11/pull/1239 diff --git a/include/CLI/StringTools.hpp b/include/CLI/StringTools.hpp index 77899fd9..d7f5ce1a 100644 --- a/include/CLI/StringTools.hpp +++ b/include/CLI/StringTools.hpp @@ -165,14 +165,12 @@ CLI11_INLINE bool valid_name_string(const std::string &str); /// Verify an app name inline bool valid_alias_name_string(const std::string &str) { - static const std::string badChars{'\n', '\0'}; - return (str.find_first_of(badChars) == std::string::npos); + return ((str.find_first_of('\n') == std::string::npos) && (str.find_first_of('\0') == std::string::npos)); } /// check if a string is a container segment separator (empty or "%%") inline bool is_separator(const std::string &str) { - static const std::string sep("%%"); - return (str.empty() || str == sep); + return (str.empty() || (str.size() == 2 && str[0] == '%' && str[1] == '%')); } /// Verify that str consists of letters only