Refactor numtostr, use calloc instead of malloc.
This commit is contained in:
parent
d78a69c83f
commit
fcea70353c
|
@ -36,7 +36,7 @@ static inline char *stostr(short value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -67,7 +67,7 @@ static inline char *itostr(int value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -98,7 +98,7 @@ static inline char *uitostr(unsigned int value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -129,7 +129,7 @@ static inline char *dtostr(double value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -160,7 +160,7 @@ static inline char *ltostr(long value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -191,7 +191,7 @@ static inline char *ultostr(unsigned long value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -222,7 +222,7 @@ static inline char *lltostr(long long value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -253,7 +253,7 @@ static inline char *ulltostr(unsigned long long value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
@ -284,7 +284,7 @@ static inline char *ftostr(float value) {
|
|||
assert(length > 0);
|
||||
|
||||
/* Attempt to allocate the string. */
|
||||
string = (char*) malloc((++length) * sizeof(char));
|
||||
string = (char*) calloc(sizeof(char), (++length));
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
|
|
Loading…
Reference in New Issue