@matheusbsbs / matheus-bagliano / commits / 83572c1a91
Fork 0

Use xrealloc instead of realloc

Change places that use realloc, without a proper error path, to instead use xrealloc. Drop an erroneous error path in the daemon code that used errno in the die message in favour of the simpler xrealloc. Signed-off-by: Jonas Fonseca <fonseca@diku.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jonas Fonseca committed Aug 26, 2006 at 16:16 UTC 83572c1a914d3f7a8dd66d954c11bbc665b7b923
9 files changed +21 -26
builtin-fmt-merge-msg.c
+2 -2
@@ -27,8 +27,8 @@ static void append_to_list(struct list *list, char *value, void *payload)
27 {
28 if (list->nr == list->alloc) {
29 list->alloc += 32;
30 - list->list = realloc(list->list, sizeof(char *) * list->alloc);
31 - list->payload = realloc(list->payload,
30 + list->list = xrealloc(list->list, sizeof(char *) * list->alloc);
31 + list->payload = xrealloc(list->payload,
32 sizeof(char *) * list->alloc);
33 }
34 list->payload[list->nr] = payload;
builtin-log.c
+2 -2
@@ -101,7 +101,7 @@ static int git_format_config(const char *var, const char *value)
101 if (!strcmp(var, "format.headers")) {
102 int len = strlen(value);
103 extra_headers_size += len + 1;
104 - extra_headers = realloc(extra_headers, extra_headers_size);
104 + extra_headers = xrealloc(extra_headers, extra_headers_size);
105 extra_headers[extra_headers_size - len - 1] = 0;
106 strcat(extra_headers, value);
107 return 0;
@@ -381,7 +381,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
381 continue;
382
383 nr++;
384 - list = realloc(list, nr * sizeof(list[0]));
384 + list = xrealloc(list, nr * sizeof(list[0]));
385 list[nr - 1] = commit;
386 }
387 total = nr;
builtin-mv.c
+3 -3
@@ -168,13 +168,13 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
168 int j, dst_len;
169
170 if (last - first > 0) {
171 - source = realloc(source,
171 + source = xrealloc(source,
172 (count + last - first)
173 * sizeof(char *));
174 - destination = realloc(destination,
174 + destination = xrealloc(destination,
175 (count + last - first)
176 * sizeof(char *));
177 - modes = realloc(modes,
177 + modes = xrealloc(modes,
178 (count + last - first)
179 * sizeof(enum update_mode));
180 }
daemon.c
+1 -6
@@ -526,7 +526,6 @@ static int socksetup(int port, int **socklist_p)
526
527 for (ai = ai0; ai; ai = ai->ai_next) {
528 int sockfd;
529 - int *newlist;
529
530 sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
531 if (sockfd < 0)
@@ -560,11 +559,7 @@ static int socksetup(int port, int **socklist_p)
559 continue; /* not fatal */
560 }
561
563 - newlist = realloc(socklist, sizeof(int) * (socknum + 1));
564 - if (!newlist)
565 - die("memory allocation failed: %s", strerror(errno));
566 -
567 - socklist = newlist;
562 + socklist = xrealloc(socklist, sizeof(int) * (socknum + 1));
563 socklist[socknum++] = sockfd;
564
565 if (maxfd < sockfd)
diff-delta.c
+1 -1
@@ -392,7 +392,7 @@ create_delta(const struct delta_index *index,
392 outsize = max_size + MAX_OP_SIZE + 1;
393 if (max_size && outpos > max_size)
394 break;
395 - out = realloc(out, outsize);
395 + out = xrealloc(out, outsize);
396 if (!out) {
397 free(tmp);
398 return NULL;
dir.c
+2 -2
@@ -101,8 +101,8 @@ void add_exclude(const char *string, const char *base,
101 x->baselen = baselen;
102 if (which->nr == which->alloc) {
103 which->alloc = alloc_nr(which->alloc);
104 - which->excludes = realloc(which->excludes,
105 - which->alloc * sizeof(x));
104 + which->excludes = xrealloc(which->excludes,
105 + which->alloc * sizeof(x));
106 }
107 which->excludes[which->nr++] = x;
108 }
git.c
+3 -3
@@ -120,7 +120,7 @@ static int split_cmdline(char *cmdline, const char ***argv)
120 ; /* skip */
121 if (count >= size) {
122 size += 16;
123 - *argv = realloc(*argv, sizeof(char*) * size);
123 + *argv = xrealloc(*argv, sizeof(char*) * size);
124 }
125 (*argv)[count++] = cmdline + dst;
126 } else if(!quoted && (c == '\'' || c == '"')) {
@@ -191,8 +191,8 @@ static int handle_alias(int *argcp, const char ***argv)
191 fflush(stderr);
192 }
193
194 - new_argv = realloc(new_argv, sizeof(char*) *
195 - (count + *argcp + 1));
194 + new_argv = xrealloc(new_argv, sizeof(char*) *
195 + (count + *argcp + 1));
196 /* insert after command name */
197 memcpy(new_argv + count, *argv + 1, sizeof(char*) * *argcp);
198 new_argv[count+*argcp] = NULL;
sha1_file.c
+1 -1
@@ -1740,7 +1740,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)
1740 off += iret;
1741 if (off == size) {
1742 size *= 2;
1743 - buf = realloc(buf, size);
1743 + buf = xrealloc(buf, size);
1744 }
1745 }
1746 } while (iret > 0);
xdiff-interface.c
+6 -6
@@ -69,9 +69,9 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
69 for (i = 0; i < nbuf; i++) {
70 if (mb[i].ptr[mb[i].size-1] != '\n') {
71 /* Incomplete line */
72 - priv->remainder = realloc(priv->remainder,
73 - priv->remainder_size +
74 - mb[i].size);
72 + priv->remainder = xrealloc(priv->remainder,
73 + priv->remainder_size +
74 + mb[i].size);
75 memcpy(priv->remainder + priv->remainder_size,
76 mb[i].ptr, mb[i].size);
77 priv->remainder_size += mb[i].size;
@@ -83,9 +83,9 @@ int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
83 consume_one(priv, mb[i].ptr, mb[i].size);
84 continue;
85 }
86 - priv->remainder = realloc(priv->remainder,
87 - priv->remainder_size +
88 - mb[i].size);
86 + priv->remainder = xrealloc(priv->remainder,
87 + priv->remainder_size +
88 + mb[i].size);
89 memcpy(priv->remainder + priv->remainder_size,
90 mb[i].ptr, mb[i].size);
91 consume_one(priv, priv->remainder,