git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] use xrealloc in help.c

From
James Bowes <jbowes@dangerouslyinc.com>
Date
Mar 28, 2007, 00:53 UTC
Message-ID
<3f80363f0703271753h631f52f4v3899b877285962@mail.gmail.com>
In-Reply-To
<118833cc0703271540l6615b413gd1df3dc5525a2d00@mail.gmail.com>

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

Signed-off-by: James Bowes <jbowes@dangerouslyinc.com>
---
On 3/27/07, Morten Welinder <mwelinder@gmail.com> wrote:
> 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(-)
diff --git a/help.c b/help.c
index be8651a..6a9af4d 100644
--- a/help.c
+++ b/help.c
@@ -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;
-- 
1.5.0.5
Previous: Morten Welinder
Message 3 of 3 in “use xrealloc in help.c”
  1. use xrealloc in help.cJames Bowes, Mar 27, 2007
  2. Morten WelinderMar 27, 2007
  3. James BowesMar 28, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.