BUG: For LESS, GREATER, and EQUAL check that the arguments can actually be converted to numbers. Also force the conversion results to be stored in memory to make sure they both use the same precision. This addresses bug#3966.

This commit is contained in:
Brad King 2006-10-25 10:31:26 -04:00
parent 9192f3638b
commit d563ab6677
1 changed files with 23 additions and 3 deletions

View File

@ -394,9 +394,29 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
double lhs;
if(sscanf(def, "%lg", &lhs) != 1)
{
cmOStringStream error;
error << "could not convert \"" << def << "\" to a number";
delete [] *errorString;
*errorString = new char[error.str().size() + 1];
strcpy(*errorString, error.str().c_str());
return false;
}
double rhs;
if(sscanf(def2, "%lg", &rhs) != 1)
{
cmOStringStream error;
error << "could not convert \"" << def2 << "\" to a number";
delete [] *errorString;
*errorString = new char[error.str().size() + 1];
strcpy(*errorString, error.str().c_str());
return false;
}
if (*(argP1) == "LESS")
{
if(atof(def) < atof(def2))
if(lhs < rhs)
{
*arg = "1";
}
@ -407,7 +427,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
}
else if (*(argP1) == "GREATER")
{
if(atof(def) > atof(def2))
if(lhs > rhs)
{
*arg = "1";
}
@ -418,7 +438,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
}
else
{
if(atof(def) == atof(def2))
if(lhs == rhs)
{
*arg = "1";
}