git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Riesen <raa.lkml@gmail.com>
To: Jim Meyering <jim@meyering.net>
Cc: git list <git@vger.kernel.org>
Subject: Re: [PATCH] use xstrdup, not strdup in ll-merge.c
Date: Mon, 15 Jun 2009 14:46:04 +0200	[thread overview]
Message-ID: <81b0412b0906150546p34ff53ceo81ea59785cf9d18a@mail.gmail.com> (raw)
In-Reply-To: <877hzdlnt6.fsf@meyering.net>

2009/6/15 Jim Meyering <jim@meyering.net>:
> Alex Riesen wrote:
>> 2009/6/15 Jim Meyering <jim@meyering.net>:
>>>
>>> Exactly.  This is why I think it's not worthwhile to invest in
>>> a more precise diagnostic, here.
>>
>> I disagree. It is already hard to find starting point for debugging if
>> the failed code is just a layer: the config of ll-merge is called not only
>> from the merge drivers, but also indirectly from the programs which
>> call the merge itself. Now, go figure where has it failed...
>
> If you're convinced of the value of such a change, go for it.

As much as I'd like to know as much as possible about why something
failed, I can't make a failure handling automatically simple (given the tools).
I do suggest using goto to handle this particular OOM (below), but it looks
almost too ugly. Maybe I am just paranoid, and am overdoing this particular
case.

> Though it sounds like you're saying you'd prefer a stack trace.

I haven't though of that, but yes, that would be perfect (except for
a small problem where it is impossible to do in a portable way,
and there is know way to get information about).

The "goto oom" patch:

diff --git a/ll-merge.c b/ll-merge.c
index 31d6f0a..4977f20 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -230,8 +230,11 @@ static int read_merge_config(const char *var,
const char *value, void *cb)
 	int namelen;

 	if (!strcmp(var, "merge.default")) {
-		if (value)
+		if (value) {
 			default_ll_merge = strdup(value);
+			if (!default_ll_merge)
+				goto oom;
+		}
 		return 0;
 	}

@@ -266,6 +269,8 @@ static int read_merge_config(const char *var,
const char *value, void *cb)
 		if (!value)
 			return error("%s: lacks value", var);
 		fn->description = strdup(value);
+		if (!fn->description)
+			goto oom;
 		return 0;
 	}

@@ -289,6 +294,8 @@ static int read_merge_config(const char *var,
const char *value, void *cb)
 		 * status.
 		 */
 		fn->cmdline = strdup(value);
+		if (!fn->cmdline)
+			goto oom;
 		return 0;
 	}

@@ -296,10 +303,15 @@ static int read_merge_config(const char *var,
const char *value, void *cb)
 		if (!value)
 			return error("%s: lacks value", var);
 		fn->recursive = strdup(value);
+		if (!fn->recursive)
+			goto oom;
 		return 0;
 	}

 	return 0;
+oom:
+	return error("line merge: %s%s%s: out of memory", var,
+		     value ? " = ": "", value ? value: "");
 }

 static void initialize_ll_merge(void)
@@ -307,7 +319,8 @@ static void initialize_ll_merge(void)
 	if (ll_user_merge_tail)
 		return;
 	ll_user_merge_tail = &ll_user_merge;
-	git_config(read_merge_config, NULL);
+	if (git_config(read_merge_config, NULL) < 0)
+		exit(1);
 }

 static const struct ll_merge_driver *find_ll_merge_driver(const char
*merge_attr)

  reply	other threads:[~2009-06-15 12:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-14 19:47 [PATCH] use xstrdup, not strdup in ll-merge.c Jim Meyering
2009-06-14 22:03 ` Alex Riesen
2009-06-15  8:02   ` Jim Meyering
2009-06-15  8:45     ` Alex Riesen
2009-06-15  9:23       ` Jim Meyering
2009-06-15 11:39         ` Alex Riesen
2009-06-15 11:49           ` Jim Meyering
2009-06-15 12:46             ` Alex Riesen [this message]
2009-06-15 14:26               ` Shawn O. Pearce
2009-06-15 15:21                 ` Alex Riesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81b0412b0906150546p34ff53ceo81ea59785cf9d18a@mail.gmail.com \
    --to=raa.lkml@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jim@meyering.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).