Prefer new over malloc

The former cannot return NULL and will allow use of scoped pointers.
This commit is contained in:
Andrew Gaul
2019-04-07 15:07:34 +09:00
parent a4ce54d615
commit 6f6a67807b
10 changed files with 76 additions and 156 deletions

View File

@ -372,9 +372,7 @@ char* s3fs_base64(const unsigned char* input, size_t length)
if(!input || 0 == length){
return NULL;
}
if(NULL == (result = reinterpret_cast<char*>(malloc((((length / 3) + 1) * 4 + 1) * sizeof(char))))){
return NULL; // ENOMEM
}
result = new char[((length / 3) + 1) * 4 + 1];
unsigned char parts[4];
size_t rpos;
@ -422,9 +420,7 @@ unsigned char* s3fs_decode64(const char* input, size_t* plength)
if(!input || 0 == strlen(input) || !plength){
return NULL;
}
if(NULL == (result = reinterpret_cast<unsigned char*>(malloc((strlen(input) + 1))))){
return NULL; // ENOMEM
}
result = new unsigned char[strlen(input) + 1];
unsigned char parts[4];
size_t input_len = strlen(input);