Replace malloc/free by new/delete. Use const char* for input arg

This commit is contained in:
Luis Díaz Más
2017-11-28 18:56:14 +01:00
parent bfe057ca20
commit 8dc3c1f0a0
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -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;
}