Skip to content

Commit

Permalink
Merge pull request #3140 from udif/pr_comment_bug
Browse files Browse the repository at this point in the history
Bugfix: core dump when 3 or more slashes (///) are found in a command-line-argument file ( -f file )
  • Loading branch information
hzeller authored Aug 9, 2022
2 parents a8bf952 + c87b94c commit b2e6116
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ std::string StringUtils::removeComments(std::string_view text) {
char c1 = '\0';
bool inComment = 0;
for (char c2 : text) {
if ((c2 == '/') && (c1 == '/')) {
if ((c2 == '/') && (c1 == '/') && !inComment) {
inComment = true;
result.erase(result.end() - 1);
}
Expand Down
1 change: 1 addition & 0 deletions src/Utils/StringUtils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ TEST(StringUtilsTest, SplitLines) {
}

TEST(StringUtilsTest, RemoveComments) {
EXPECT_EQ("hello ", StringUtils::removeComments("hello /// world"));
EXPECT_EQ("hello ", StringUtils::removeComments("hello // world"));
EXPECT_EQ("hello ", StringUtils::removeComments("hello # world"));
EXPECT_EQ("hello \nworld",
Expand Down

0 comments on commit b2e6116

Please sign in to comment.