Ashim Kapoor: deal with backspace better (#694)

This commit is contained in:
Daniel Marjamäki 2009-09-29 17:02:19 +02:00
parent ededbfb10e
commit 12b29e35ad
2 changed files with 16 additions and 4 deletions

View File

@ -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;
}

View File

@ -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()