diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index aa2246390..f0172e71e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -598,6 +598,25 @@ static void valueFlowNumber(TokenList *tokenlist) ValueFlow::Value value(MathLib::toLongNumber(tok->str())); value.setKnown(); setTokenValue(tok, value); + } else if (tok->tokType() == Token::eChar) { + char c; + if (tok->str() == "\'\\n\'") + c = '\n'; + else if (tok->str() == "\'\\r\'") + c = '\r'; + else if (tok->str() == "\'\\t\'") + c = '\t'; + else if (tok->str().size() == 3U && + tok->str()[0] == '\'' && + (tok->str()[1] & 0x80) == 0 && + tok->str()[2] == '\'') + c = tok->str()[1]; + else + continue; + + ValueFlow::Value value(c); + value.setKnown(); + setTokenValue(tok, value); } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 730300a8c..7cf3f6c84 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -165,8 +165,10 @@ private: void valueFlowNumber() { ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue); - ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue); - ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue); + ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue); + ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue); + ASSERT_EQUALS((int)('a'), valueOfTok("x='a';", "'a'").intvalue); + ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue); } void valueFlowString() {