Skip to content

Commit

Permalink
compat/setenv.c: update errno when erroring out
Browse files Browse the repository at this point in the history
Previously, gitsetenv didn't update errno as it should when
erroring out. Fix this.

Signed-off-by: Erik Faye-Lund <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
kusma authored and gitster committed Dec 15, 2011
1 parent 10dd3b2 commit 57590c7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions compat/setenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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] = '=';
Expand Down

0 comments on commit 57590c7

Please sign in to comment.