Skip to contentSkip to conversation

use xrealloc in help.c

PATCH In review James Bowes 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 use xrealloc in help.c

---
 help.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
help.c +1 -1
index be8651a..34b1dda 100644
@@ -54,7 +54,7 @@ static void add_cmdname(const char *name, int len)
 	struct cmdname *ent;
 	if (cmdname_alloc <= cmdname_cnt) {
 		cmdname_alloc = cmdname_alloc + 200;
-		cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));
+		cmdname = xrealloc(cmdname, cmdname_alloc * sizeof(*cmdname));
 		if (!cmdname)
 			oom();
 	}
Signature · 1 line
1.5.0.5
#1 lore raw

help.c static void add_cmdname(const char *name, int len) · line 59

Quoted 4 lines
help.c +1 -1
-               cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));
+               cmdname = xrealloc(cmdname, cmdname_alloc * sizeof(*cmdname));
                if (!cmdname)
                        oom();

If you are using xrealloc, shouldn't kill the oom check here too?

M.

#2 lore raw

oom() is not needed any more either, since the x* functions check the return themselves. So get rid of it.

---

Quoted 1 line · Morten Welinder

If you are using xrealloc, shouldn't kill the oom check here too?

Good point. There's no need for oom() at all then, anymore.

help.c | 12 +-----------

1 files changed, 1 insertions(+), 11 deletions(-)
help.c +0 -0
index be8651a..6a9af4d 100644
@@ -31,12 +31,6 @@ static int term_columns(void)
	return 80;
}

-static void oom(void)
-{
- fprintf(stderr, "git: out of memory\n");
- exit(1);
-}
-
static inline void mput_char(char c, unsigned int num)

{
	while(num--)
@@ -54,13 +48,9 @@ static void add_cmdname(const char *name, int len)
	struct cmdname *ent;
	if (cmdname_alloc <= cmdname_cnt) {
		cmdname_alloc = cmdname_alloc + 200;
-		cmdname = realloc(cmdname, cmdname_alloc * sizeof(*cmdname));
-		if (!cmdname)
-			oom();
+		cmdname = xrealloc(cmdname, cmdname_alloc * sizeof(*cmdname));
	}
	ent = xmalloc(sizeof(*ent) + len);
-	if (!ent)
-		oom();
	ent->len = len;
	memcpy(ent->name, name, len);
	ent->name[len] = 0;
Signature · 1 line
1.5.0.5