Fixed ticket #417 (Crashes in windows because of invalid char value)
negative char values are allowed in strings and comments. but not in other code.
This commit is contained in:
parent
f523b118ab
commit
58c7414ce0
|
@ -262,7 +262,7 @@ std::string Preprocessor::read(std::istream &istr)
|
|||
++lineno;
|
||||
|
||||
// Replace assorted special chars with spaces..
|
||||
if ((ch != '\n') && (std::isspace(ch) || std::iscntrl(ch)))
|
||||
if ((ch > 0) && (ch != '\n') && (std::isspace(ch) || std::iscntrl(ch)))
|
||||
ch = ' ';
|
||||
|
||||
// Skip spaces after ' ' and after '#'
|
||||
|
@ -274,7 +274,7 @@ std::string Preprocessor::read(std::istream &istr)
|
|||
{
|
||||
if (ch == '(')
|
||||
code << " ";
|
||||
else if (! std::isalpha(ch))
|
||||
else if ((ch > 0) && ! std::isalpha(ch))
|
||||
needSpace = false;
|
||||
}
|
||||
if (ch == '#')
|
||||
|
@ -287,7 +287,7 @@ std::string Preprocessor::read(std::istream &istr)
|
|||
while (true)
|
||||
{
|
||||
chNext = (char)istr.peek();
|
||||
if (chNext != '\n' && chNext != '\r' &&
|
||||
if (chNext != '\n' && chNext != '\r' && (chNext > 0) &&
|
||||
(std::isspace(chNext) || std::iscntrl(chNext)))
|
||||
{
|
||||
// Skip whitespace between <backspace> and <newline>
|
||||
|
|
|
@ -126,7 +126,9 @@ private:
|
|||
TEST_CASE(endifsemicolon);
|
||||
TEST_CASE(missing_doublequote);
|
||||
|
||||
TEST_CASE(unicode1);
|
||||
TEST_CASE(unicodeInCode);
|
||||
TEST_CASE(unicodeInComment);
|
||||
TEST_CASE(unicodeInString);
|
||||
TEST_CASE(define_part_of_func);
|
||||
TEST_CASE(conditionalDefine);
|
||||
TEST_CASE(multiline_comment);
|
||||
|
@ -996,13 +998,28 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void unicode1()
|
||||
void unicodeInCode()
|
||||
{
|
||||
const char filedata[] = {'a', (char)200, 0};
|
||||
const std::string filedata(std::string("a") + char(200));
|
||||
std::istringstream istr(filedata);
|
||||
ASSERT_THROW(Preprocessor::read(istr), std::runtime_error);
|
||||
}
|
||||
|
||||
void unicodeInComment()
|
||||
{
|
||||
const std::string filedata(std::string("//") + char(200));
|
||||
std::istringstream istr(filedata.c_str());
|
||||
ASSERT_EQUALS("", Preprocessor::read(istr));
|
||||
}
|
||||
|
||||
void unicodeInString()
|
||||
{
|
||||
const std::string filedata(std::string("\"") + char(200) + "\"");
|
||||
std::istringstream istr(filedata.c_str());
|
||||
ASSERT_EQUALS(filedata, Preprocessor::read(istr));
|
||||
}
|
||||
|
||||
|
||||
void define_part_of_func()
|
||||
{
|
||||
errout.str("");
|
||||
|
|
Loading…
Reference in New Issue