I have a problem with my C++ code as valgrind is giving me the error (Conditional jump or move depends on uninitialized value(s)) at lines highlighted below. I tried initializing "type" with an empty string, but doesn't seems to be working. Any help here much appreciated.
Many thanks in advance.
nandanator
int AB_CD::checkType(string & str)
{
int tmp = 0;
string type;
while (getNextSubstring(str, type))
{
if (type == "AAA") <<<<< ----- Valgrind error pointing here
{
tmp |= static_cast<int>(TYPE_AAA);
}
else if (type == "BBB") <<<<< ----- Valgrind error pointing here
{
tmp |= static_cast<int>(TYPE_BBB);
}
else if (type == "CCC") <<<<< ----- Valgrind error pointing here
{
tmp |= static_cast<int>(TYPE_CCC);
}
else
{
//Print a warning
}
}
return tmp;
}
bool AB_CD::getNextSubstring(string & input, string & substring)
{
bool found_substring = false;
string::size_type start = input.find_first_not_of(" ,");
string::size_type end = input.find_first_of(" ,", start);
if (start != string::npos)
{
substring = input.substr(start, end-start);
input.erase(start, end-start);
found_substring = true;
}
return found_substring;
}