Fixed #7424 (value type: wrong sign)

This commit is contained in:
Robert Reif 2016-03-18 10:30:57 +01:00 committed by Daniel Marjamäki
parent ea889acfdc
commit 100c4276ea
4 changed files with 8 additions and 10 deletions

View File

@ -54,6 +54,9 @@ MathLib::value::value(const std::string &s) :
type = MathLib::value::INT;
intValue = MathLib::toLongNumber(s);
if (isIntHex(s) && intValue < 0)
isUnsigned = true;
// read suffix
if (s.size() >= 2U) {
for (std::size_t i = s.size() - 1U; i > 0U; --i) {
@ -93,9 +96,10 @@ std::string MathLib::value::str() const
return ret.substr(0, pos+1);
}
ostr << intValue;
if (isUnsigned)
ostr << "U";
ostr << static_cast<biguint>(intValue) << "U";
else
ostr << intValue;
if (type == MathLib::value::LONG)
ostr << "L";
else if (type == MathLib::value::LONGLONG)

View File

@ -129,9 +129,7 @@ void TokenList::addtoken(std::string str, const unsigned int lineno, const unsig
// Replace hexadecimal value with decimal
if (MathLib::isIntHex(str) || MathLib::isOct(str) || MathLib::isBin(str)) {
std::ostringstream str2stream;
str2stream << MathLib::toULongNumber(str);
str = str2stream.str();
str = MathLib::value(str).str();
} else if (str.compare(0, 5, "_Bool") == 0) {
str = "bool";
}

View File

@ -5745,11 +5745,7 @@ private:
check("void f(unsigned long long ull) {\n"
" if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n"
"}\n");
#if defined(_MSC_VER) && defined(_M_AMD64)
TODO_ASSERT_EQUALS("", "[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '||'.\n", errout.str());
#else
ASSERT_EQUALS("", errout.str());
#endif
}
void redundantPointerOp() {

View File

@ -45,7 +45,7 @@ private:
const std::string code = "0x89504e470d0a1a0a";
TokenList tokenlist(&settings);
tokenlist.addtoken(code, 1, 1, false);
ASSERT_EQUALS("9894494448401390090", tokenlist.front()->str());
ASSERT_EQUALS("9894494448401390090U", tokenlist.front()->str());
// that is supposed to break on 32bit
//unsigned long numberUL(0);
//std::istringstream(tokenlist.front()->str()) >> numberUL;