git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Faye-Lund <kusmabite@gmail.com>
To: git@vger.kernel.org
Cc: peff@peff.net, gitster@pobox.com, schwab@linux-m68k.org
Subject: [PATCH v2 1/4] compat/setenv.c: update errno when erroring out
Date: Wed, 14 Dec 2011 15:07:08 +0100	[thread overview]
Message-ID: <1323871631-2872-2-git-send-email-kusmabite@gmail.com> (raw)
In-Reply-To: <1323871631-2872-1-git-send-email-kusmabite@gmail.com>

Previously, gitsetenv didn't update errno as it should when
erroring out. Fix this.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
 compat/setenv.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/compat/setenv.c b/compat/setenv.c
index 3a22ea7..89947b7 100644
--- a/compat/setenv.c
+++ b/compat/setenv.c
@@ -6,7 +6,10 @@ int gitsetenv(const char *name, const char *value, int replace)
 	size_t namelen, valuelen;
 	char *envstr;
 
-	if (!name || !value) return -1;
+	if (!name || !value) {
+		errno = EINVAL;
+		return -1;
+	}
 	if (!replace) {
 		char *oldval = NULL;
 		oldval = getenv(name);
@@ -16,7 +19,10 @@ int gitsetenv(const char *name, const char *value, int replace)
 	namelen = strlen(name);
 	valuelen = strlen(value);
 	envstr = malloc((namelen + valuelen + 2));
-	if (!envstr) return -1;
+	if (!envstr) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	memcpy(envstr, name, namelen);
 	envstr[namelen] = '=';
-- 
1.7.7.1.msysgit.0.272.g9e47e

  reply	other threads:[~2011-12-14 14:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-14 14:07 [PATCH v2 0/4] setenv/putenv errors Erik Faye-Lund
2011-12-14 14:07 ` Erik Faye-Lund [this message]
2011-12-14 14:07 ` [PATCH v2 2/4] compat/setenv.c: error if name contains '=' Erik Faye-Lund
2011-12-14 14:07 ` [PATCH v2 3/4] wrapper: supply xsetenv and xputenv Erik Faye-Lund
2011-12-15 17:38   ` Junio C Hamano
2011-12-15 18:25     ` Erik Faye-Lund
2011-12-14 14:07 ` [PATCH v2 4/4] use wrapper for unchecked setenv/putenv calls Erik Faye-Lund
2011-12-14 18:16   ` Jeff King
2011-12-15 18:04     ` Erik Faye-Lund

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=1323871631-2872-2-git-send-email-kusmabite@gmail.com \
    --to=kusmabite@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=schwab@linux-m68k.org \
    /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).