Browse Source

return value of realloc now written in tmp variable for proper handling of realloc errors

master
T. Meissner 10 years ago
parent
commit
d6aba8cb68
1 changed files with 4 additions and 2 deletions
  1. +4
    -2
      21st_century_c/chapter11/dict.c

+ 4
- 2
21st_century_c/chapter11/dict.c View File

@ -28,8 +28,10 @@ dictionary *dictionary_new(void) {
static void dictionary_add_keyval(dictionary *in, keyval *kv) {
in->length++;
in->pairs = realloc(in->pairs, sizeof(keyval*) * in->length);
if(in->pairs != NULL) {
keyval **tmp = realloc(in->pairs, sizeof(keyval*) * in->length);
if(tmp != NULL) {
in->pairs = tmp;
tmp = NULL;
in->pairs[in->length-1] = kv;
} else {
fprintf(stderr, "Out of memory.\n");


Loading…
Cancel
Save