|
@@ -214,20 +214,19 @@ void * realloc(void *ptr, size_t size) {
|
|
|
}
|
|
|
|
|
|
void * calloc(size_t nmemb, size_t size) {
|
|
|
- size_t i;
|
|
|
- char *buf[nmemb];
|
|
|
+ void *result;
|
|
|
|
|
|
if(nmemb == 0 || size == 0) {
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
- i = 0;
|
|
|
+ size_t total_size = nmemb * size;
|
|
|
|
|
|
- while(i < nmemb) {
|
|
|
- buf[i] = (char*)malloc(size);
|
|
|
- memset(buf[i], '\0', size);
|
|
|
- i++;
|
|
|
+ result = malloc(total_size);
|
|
|
+
|
|
|
+ if(result != NULL) {
|
|
|
+ memset(result, 0, total_size);
|
|
|
}
|
|
|
|
|
|
- return buf[0];
|
|
|
+ return result;
|
|
|
}
|