From d563ab6677ae5a1e871a528208351eba46942eca Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 25 Oct 2006 10:31:26 -0400 Subject: [PATCH] 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. --- Source/cmIfCommand.cxx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index d8956db81..9dcaf9be5 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -394,9 +394,29 @@ bool cmIfCommand::IsTrue(const std::vector &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 &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 &args, } else { - if(atof(def) == atof(def2)) + if(lhs == rhs) { *arg = "1"; }