Skip to content

Commit bfffd37

Browse files
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>
1 parent 8ddadd7 commit bfffd37

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ and a potential segmentation fault from specially crafted config files
1717
- Fixed incorrect inclusion of definition for extra validators [#1238][]
1818
- Fixed fuzz generated failure from crafted files introduced in recent release
1919
[#1238][]
20+
- Removed some usage of static const std::string in inline function that had
21+
potential memory issues when CLI11 is used with shared libraries, this likely
22+
isn't a bug but the fix did result in smaller code size so was kept. [#1244][]
2023

24+
[#1244]: https://github.com/CLIUtils/CLI11/pull/1244
2125
[#1238]: https://github.com/CLIUtils/CLI11/pull/1238
2226
[#1239]: https://github.com/CLIUtils/CLI11/pull/1239
2327

include/CLI/StringTools.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,12 @@ CLI11_INLINE bool valid_name_string(const std::string &str);
165165

166166
/// Verify an app name
167167
inline bool valid_alias_name_string(const std::string &str) {
168-
static const std::string badChars{'\n', '\0'};
169-
return (str.find_first_of(badChars) == std::string::npos);
168+
return ((str.find_first_of('\n') == std::string::npos) && (str.find_first_of('\0') == std::string::npos));
170169
}
171170

172171
/// check if a string is a container segment separator (empty or "%%")
173172
inline bool is_separator(const std::string &str) {
174-
static const std::string sep("%%");
175-
return (str.empty() || str == sep);
173+
return (str.empty() || (str.size() == 2 && str[0] == '%' && str[1] == '%'));
176174
}
177175

178176
/// Verify that str consists of letters only

0 commit comments

Comments
 (0)