Fixed #4433 (Wrong array size for string with \0)

This commit is contained in:
Daniel Marjamäki 2012-12-26 12:08:40 +01:00
parent ce380301fd
commit b3301a9ef9
3 changed files with 8 additions and 10 deletions

View File

@ -8037,13 +8037,8 @@ std::string Tokenizer::simplifyString(const std::string &source)
sz++;
std::istringstream istr(str.substr(i+1, sz-1));
istr >> std::oct >> c;
if (sz == 2) {
if (c == 0) {
str = str.substr(0,i) + "\"";
continue;
} else
str[i+1] = (char)c;
}
str = str.substr(0,i) + (char)c + str.substr(i+sz);
continue;
}
if (sz <= 2)

View File

@ -848,8 +848,11 @@ private:
const char code2[] = "char str [ ] = \"\\x00\";";
const char expected2[] = "char str [ 2 ] = \"\\0\" ;";
std::string actual = tok(code2);
ASSERT_EQUALS(expected2, actual);
ASSERT_EQUALS(expected2, tok(code2));
const char code3[] = "char str [ ] = \"\\0\";";
const char expected3[] = "char str [ 2 ] = \"\\0\" ;";
ASSERT_EQUALS(expected3, tok(code3));
}
void dontRemoveIncrement() {

View File

@ -6005,7 +6005,7 @@ private:
ASSERT_EQUALS("\" 7\"", tokenizer.simplifyString("\"\\0407\""));
// terminate a string at null character.
ASSERT_EQUALS("\"a\"", tokenizer.simplifyString("\"a\\0\""));
ASSERT_EQUALS(std::string("\"a") + '\0' + "\"", tokenizer.simplifyString("\"a\\0\""));
}
void simplifyConst() {