summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorschu <schu-github@schulog.org>2011-08-17 15:20:43 +0200
committerschu <schu-github@schulog.org>2011-08-17 15:24:48 +0200
commit31e5909214cbfba0c43143288a77f2fc067004f7 (patch)
tree52acd57fe9017fb4fef02c36aa8ab6cae8a4e561 /src/util.h
parent5a0659fe3ba020181a07464c4c92b06a5c21b43a (diff)
downloadlibgit2-31e5909214cbfba0c43143288a77f2fc067004f7.tar.gz
git__strndup: immediately return NULL when ENOMEM
Signed-off-by: schu <schu-github@schulog.org>
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/util.h b/src/util.h
index 18929af8e..f70bfe743 100644
--- a/src/util.h
+++ b/src/util.h
@@ -47,11 +47,13 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
length = n;
ptr = (char*)malloc(length + 1);
- if (!ptr)
+ if (!ptr) {
git__throw(GIT_ENOMEM, "Out of memory. Failed to duplicate string");
+ return NULL;
+ }
memcpy(ptr, str, length);
- ptr[length] = 0;
+ ptr[length] = '\0';
return ptr;
}