From 6e2b18535bf3ffd9400d73462fd2a0f1a609664e Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Sat, 23 Sep 2017 14:39:20 +0200 Subject: cmCPluginAPI: use strdup() instead of open coding it --- Source/cmCPluginAPI.cxx | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index e259f4d..8b6fd97 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -405,14 +405,8 @@ char CCONV* cmExpandVariablesInString(void* arg, const char* source, { cmMakefile* mf = static_cast(arg); std::string barf = source; - std::string result = mf->ExpandVariablesInString( - barf, (escapeQuotes ? true : false), (atOnly ? true : false)); - char* res = static_cast(malloc(result.size() + 1)); - if (!result.empty()) { - strcpy(res, result.c_str()); - } - res[result.size()] = '\0'; - return res; + std::string result = mf->ExpandVariablesInString(barf, escapeQuotes, atOnly); + return strdup(result.c_str()); } int CCONV cmExecuteCommand(void* arg, const char* name, int numArgs, @@ -762,25 +756,19 @@ void CCONV cmSourceFileSetName2(void* arg, const char* name, const char* dir, char* CCONV cmGetFilenameWithoutExtension(const char* name) { std::string sres = cmSystemTools::GetFilenameWithoutExtension(name); - char* result = (char*)malloc(sres.size() + 1); - strcpy(result, sres.c_str()); - return result; + return strdup(sres.c_str()); } char* CCONV cmGetFilenamePath(const char* name) { std::string sres = cmSystemTools::GetFilenamePath(name); - char* result = (char*)malloc(sres.size() + 1); - strcpy(result, sres.c_str()); - return result; + return strdup(sres.c_str()); } char* CCONV cmCapitalized(const char* name) { std::string sres = cmSystemTools::Capitalized(name); - char* result = (char*)malloc(sres.size() + 1); - strcpy(result, sres.c_str()); - return result; + return strdup(sres.c_str()); } void CCONV cmCopyFileIfDifferent(const char* name1, const char* name2) -- cgit v0.12 From cf3990365a8b1b9777a832b321eeeefc29716fd4 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Sat, 23 Sep 2017 14:57:34 +0200 Subject: cmCPluginAPI: do not check pointer before calling free() --- Source/cmCPluginAPI.cxx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 8b6fd97..eee18c0 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -454,9 +454,7 @@ void CCONV cmFreeArguments(int argc, char** argv) for (i = 0; i < argc; ++i) { free(argv[i]); } - if (argv) { - free(argv); - } + free(argv); } int CCONV cmGetTotalArgumentSize(int argc, char** argv) -- cgit v0.12 From 0332ec72b287ae464a67002fb6b9057e772f19af Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Sat, 23 Sep 2017 14:57:51 +0200 Subject: cmCPluginAPI: remove explicit casts to void* --- Source/cmCPluginAPI.cxx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index eee18c0..e1e11af 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -505,13 +505,12 @@ cmCPluginAPISourceFileMap cmCPluginAPISourceFiles; void* CCONV cmCreateSourceFile(void) { - return (void*)new cmCPluginAPISourceFile; + return new cmCPluginAPISourceFile; } void* CCONV cmCreateNewSourceFile(void*) { - cmCPluginAPISourceFile* sf = new cmCPluginAPISourceFile; - return (void*)sf; + return new cmCPluginAPISourceFile; } void CCONV cmDestroySourceFile(void* arg) @@ -544,7 +543,7 @@ void CCONV* cmGetSource(void* arg, const char* name) cmCPluginAPISourceFileMap::value_type entry(rsf, sf); i = cmCPluginAPISourceFiles.insert(entry).first; } - return (void*)i->second; + return i->second; } return nullptr; } @@ -573,7 +572,7 @@ void* CCONV cmAddSource(void* arg, void* arg2) // Store the proxy in the map so it can be re-used and deleted later. cmCPluginAPISourceFiles[rsf] = sf; - return (void*)sf; + return sf; } const char* CCONV cmSourceFileGetSourceName(void* arg) -- cgit v0.12