ERR: Fix warnings and memory leak

This commit is contained in:
Andy Cedilnik 2004-08-04 08:50:37 -04:00
parent 2938652cbd
commit 87cab828b6

View File

@ -122,6 +122,7 @@ bool cmIfCommand::InvokeInitialPass(const std::vector<cmListFileArgument>& args)
err += errorString; err += errorString;
err += ")."; err += ").";
this->SetError(err.c_str()); this->SetError(err.c_str());
delete [] errorString;
return false; return false;
} }
@ -152,13 +153,16 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
char **errorString, const cmMakefile *makefile) char **errorString, const cmMakefile *makefile)
{ {
// check for the different signatures // check for the different signatures
*errorString = "Unknown arguments specified";
const char *def; const char *def;
const char *def2; const char *def2;
const char* msg = "Unknown arguments specified";
*errorString = new char[strlen(msg) + 1];
strcpy(*errorString, msg);
// handle empty invocation // handle empty invocation
if (args.size() < 1) if (args.size() < 1)
{ {
delete [] *errorString;
*errorString = 0; *errorString = 0;
return false; return false;
} }
@ -169,11 +173,12 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
// test started failing because the minor version went to zero this causes // test started failing because the minor version went to zero this causes
// the test to pass // the test to pass
if (args.size() == 3 && if (args.size() == 3 &&
(makefile->GetDefinition("VTKTIFF_SOURCE_DIR") || (makefile->GetDefinition("VTKTIFF_SOURCE_DIR") ||
makefile->GetDefinition("ITKTIFF_SOURCE_DIR")) && makefile->GetDefinition("ITKTIFF_SOURCE_DIR")) &&
args[0] == "CMAKE_MINOR_VERSION" && args[0] == "CMAKE_MINOR_VERSION" &&
args[1] == "MATCHES") args[1] == "MATCHES")
{ {
delete [] *errorString;
*errorString = 0; *errorString = 0;
return true; return true;
} }
@ -279,7 +284,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
argP2 = argP1; argP2 = argP1;
argP2++; argP2++;
if (argP1 != newArgs.end() && argP2 != newArgs.end() && if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
*(argP1) == "MATCHES") *(argP1) == "MATCHES")
{ {
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile); def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
const char* rex = (argP2)->c_str(); const char* rex = (argP2)->c_str();
@ -288,6 +293,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
{ {
cmOStringStream error; cmOStringStream error;
error << "Regular expression \"" << rex << "\" cannot compile"; error << "Regular expression \"" << rex << "\" cannot compile";
delete [] *errorString;
*errorString = new char[error.str().size() + 1]; *errorString = new char[error.str().size() + 1];
strcpy(*errorString, error.str().c_str()); strcpy(*errorString, error.str().c_str());
return false; return false;
@ -321,8 +327,8 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
} }
if (argP1 != newArgs.end() && argP2 != newArgs.end() && if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
(*(argP1) == "LESS" || *(argP1) == "GREATER" || (*(argP1) == "LESS" || *(argP1) == "GREATER" ||
*(argP1) == "EQUAL")) *(argP1) == "EQUAL"))
{ {
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile); def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile); def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
@ -369,9 +375,9 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
} }
if (argP1 != newArgs.end() && argP2 != newArgs.end() && if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
(*(argP1) == "STRLESS" || (*(argP1) == "STRLESS" ||
*(argP1) == "STREQUAL" || *(argP1) == "STREQUAL" ||
*(argP1) == "STRGREATER")) *(argP1) == "STRGREATER"))
{ {
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile); def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile); def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
@ -460,7 +466,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
argP2 = argP1; argP2 = argP1;
argP2++; argP2++;
if (argP1 != newArgs.end() && *(argP1) == "AND" && if (argP1 != newArgs.end() && *(argP1) == "AND" &&
argP2 != newArgs.end()) argP2 != newArgs.end())
{ {
def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile); def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile);
def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile); def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile);
@ -482,7 +488,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
} }
if (argP1 != newArgs.end() && *(argP1) == "OR" && if (argP1 != newArgs.end() && *(argP1) == "OR" &&
argP2 != newArgs.end()) argP2 != newArgs.end())
{ {
def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile); def = cmIfCommand::GetVariableOrNumber(arg->c_str(), makefile);
def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile); def2 = cmIfCommand::GetVariableOrNumber((argP2)->c_str(), makefile);
@ -511,6 +517,7 @@ bool cmIfCommand::IsTrue(const std::vector<std::string> &args,
// now at the end there should only be one argument left // now at the end there should only be one argument left
if (newArgs.size() == 1) if (newArgs.size() == 1)
{ {
delete [] *errorString;
*errorString = 0; *errorString = 0;
if (*newArgs.begin() == "0") if (*newArgs.begin() == "0")
{ {