From 8dc3c1f0a0e9bdd09481dac1d2c0a0d1ad4667b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20D=C3=ADaz=20M=C3=A1s?= Date: Tue, 28 Nov 2017 18:56:14 +0100 Subject: [PATCH] Replace malloc/free by new/delete. Use const char* for input arg --- include/exiv2/futils.hpp | 2 +- src/futils.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/exiv2/futils.hpp b/include/exiv2/futils.hpp index 5a322fc9..2bd71239 100644 --- a/include/exiv2/futils.hpp +++ b/include/exiv2/futils.hpp @@ -78,7 +78,7 @@ namespace Exiv2 { @note Be sure to free() the returned string after use Source: http://www.geekhideout.com/urlcode.shtml */ - EXIV2API std::string urlencode(char *str); + EXIV2API std::string urlencode(const char *str); /*! @brief Decode the input url. @param str The url needs decoding. diff --git a/src/futils.cpp b/src/futils.cpp index 88c5c1df..9b345fdf 100644 --- a/src/futils.cpp +++ b/src/futils.cpp @@ -71,9 +71,9 @@ namespace Exiv2 { return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; } // from_hex - std::string urlencode(char* str) { - char* pstr = str; - char* buf = (char*)malloc(strlen(str) * 3 + 1); + std::string urlencode(const char* str) { + const char* pstr = str; + char* buf = new char[strlen(str) * 3 + 1]; char* pbuf = buf; while (*pstr) { if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') @@ -86,7 +86,7 @@ namespace Exiv2 { } *pbuf = '\0'; std::string ret(buf); - free(buf); + delete [] buf; return ret; }