summaryrefslogtreecommitdiff
path: root/src/util/allocators/stdalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/allocators/stdalloc.c')
-rw-r--r--src/util/allocators/stdalloc.c107
1 files changed, 2 insertions, 105 deletions
diff --git a/src/util/allocators/stdalloc.c b/src/util/allocators/stdalloc.c
index 2b36d9f3d..f2d72a7e6 100644
--- a/src/util/allocators/stdalloc.c
+++ b/src/util/allocators/stdalloc.c
@@ -9,8 +9,6 @@
static void *stdalloc__malloc(size_t len, const char *file, int line)
{
- void *ptr;
-
GIT_UNUSED(file);
GIT_UNUSED(line);
@@ -19,86 +17,11 @@ static void *stdalloc__malloc(size_t len, const char *file, int line)
return NULL;
#endif
- ptr = malloc(len);
-
- if (!ptr)
- git_error_set_oom();
-
- return ptr;
-}
-
-static void *stdalloc__calloc(size_t nelem, size_t elsize, const char *file, int line)
-{
- void *ptr;
-
- GIT_UNUSED(file);
- GIT_UNUSED(line);
-
-#ifdef GIT_DEBUG_STRICT_ALLOC
- if (!elsize || !nelem)
- return NULL;
-#endif
-
- ptr = calloc(nelem, elsize);
-
- if (!ptr)
- git_error_set_oom();
-
- return ptr;
-}
-
-static char *stdalloc__strdup(const char *str, const char *file, int line)
-{
- char *ptr;
-
- GIT_UNUSED(file);
- GIT_UNUSED(line);
-
- ptr = strdup(str);
-
- if (!ptr)
- git_error_set_oom();
-
- return ptr;
-}
-
-static char *stdalloc__strndup(const char *str, size_t n, const char *file, int line)
-{
- size_t length = 0, alloclength;
- char *ptr;
-
- length = p_strnlen(str, n);
-
- if (GIT_ADD_SIZET_OVERFLOW(&alloclength, length, 1) ||
- !(ptr = stdalloc__malloc(alloclength, file, line)))
- return NULL;
-
- if (length)
- memcpy(ptr, str, length);
-
- ptr[length] = '\0';
-
- return ptr;
-}
-
-static char *stdalloc__substrdup(const char *start, size_t n, const char *file, int line)
-{
- char *ptr;
- size_t alloclen;
-
- if (GIT_ADD_SIZET_OVERFLOW(&alloclen, n, 1) ||
- !(ptr = stdalloc__malloc(alloclen, file, line)))
- return NULL;
-
- memcpy(ptr, start, n);
- ptr[n] = '\0';
- return ptr;
+ return malloc(len);
}
static void *stdalloc__realloc(void *ptr, size_t size, const char *file, int line)
{
- void *new_ptr;
-
GIT_UNUSED(file);
GIT_UNUSED(line);
@@ -107,27 +30,7 @@ static void *stdalloc__realloc(void *ptr, size_t size, const char *file, int lin
return NULL;
#endif
- new_ptr = realloc(ptr, size);
-
- if (!new_ptr)
- git_error_set_oom();
-
- return new_ptr;
-}
-
-static void *stdalloc__reallocarray(void *ptr, size_t nelem, size_t elsize, const char *file, int line)
-{
- size_t newsize;
-
- if (GIT_MULTIPLY_SIZET_OVERFLOW(&newsize, nelem, elsize))
- return NULL;
-
- return stdalloc__realloc(ptr, newsize, file, line);
-}
-
-static void *stdalloc__mallocarray(size_t nelem, size_t elsize, const char *file, int line)
-{
- return stdalloc__reallocarray(NULL, nelem, elsize, file, line);
+ return realloc(ptr, size);
}
static void stdalloc__free(void *ptr)
@@ -138,13 +41,7 @@ static void stdalloc__free(void *ptr)
int git_stdalloc_init_allocator(git_allocator *allocator)
{
allocator->gmalloc = stdalloc__malloc;
- allocator->gcalloc = stdalloc__calloc;
- allocator->gstrdup = stdalloc__strdup;
- allocator->gstrndup = stdalloc__strndup;
- allocator->gsubstrdup = stdalloc__substrdup;
allocator->grealloc = stdalloc__realloc;
- allocator->greallocarray = stdalloc__reallocarray;
- allocator->gmallocarray = stdalloc__mallocarray;
allocator->gfree = stdalloc__free;
return 0;
}