diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index e35d32bee..237a10ce7 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -833,9 +833,6 @@ int CheckBufferOverrun::count(const std::string &input_string) case '%': if (flag == 1) flag = 0; break; - case '/': - input_string_size--; - break; } if (flag) input_string_size++; @@ -857,6 +854,21 @@ int CheckBufferOverrun::count(const std::string &input_string) } + // A second iteration through the string to deal with /'s + + std::string::size_type j = 0; + + while (j < input_string.size()) + { + if (input_string[j] == '\\') + { + input_string_size--; + j += 2; + continue; + } + j++; + } + return input_string_size + 1 + digits; } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 0552ace4b..2490a9b67 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -896,7 +896,7 @@ private: ASSERT_EQUALS(3, CheckBufferOverrun::count("%2.2d")); ASSERT_EQUALS(1, CheckBufferOverrun::count("%s")); ASSERT_EQUALS(6, CheckBufferOverrun::count("%-5s")); - TODO_ASSERT_EQUALS(2, CheckBufferOverrun::count("\\\"")); + ASSERT_EQUALS(2, CheckBufferOverrun::count("\\\"")); } void strncpy1()