Commit 31e59092 by schu

git__strndup: immediately return NULL when ENOMEM

Signed-off-by: schu <schu-github@schulog.org>
parent 5a0659fe
...@@ -47,11 +47,13 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n) ...@@ -47,11 +47,13 @@ GIT_INLINE(char *) git__strndup(const char *str, size_t n)
length = n; length = n;
ptr = (char*)malloc(length + 1); ptr = (char*)malloc(length + 1);
if (!ptr) if (!ptr) {
git__throw(GIT_ENOMEM, "Out of memory. Failed to duplicate string"); git__throw(GIT_ENOMEM, "Out of memory. Failed to duplicate string");
return NULL;
}
memcpy(ptr, str, length); memcpy(ptr, str, length);
ptr[length] = 0; ptr[length] = '\0';
return ptr; return ptr;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment