diff options
author | Brad King <brad.king@kitware.com> | 2006-10-25 14:31:26 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2006-10-25 14:31:26 (GMT) |
commit | d563ab6677ae5a1e871a528208351eba46942eca (patch) | |
tree | 2740c583a7effb8684e3fc2cb87c0b67c429ac0e /Source/cmIfCommand.cxx | |
parent | 9192f3638b28b69b899f9dd89aec2e8915043e99 (diff) | |
download | CMake-d563ab6677ae5a1e871a528208351eba46942eca.zip CMake-d563ab6677ae5a1e871a528208351eba46942eca.tar.gz CMake-d563ab6677ae5a1e871a528208351eba46942eca.tar.bz2 |
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.
Diffstat (limited to 'Source/cmIfCommand.cxx')
-rw-r--r-- | Source/cmIfCommand.cxx | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index d8956db..9dcaf9b 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -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"; } |