From 0eec6dcddb60bd17c5227d8da94cb06bf8b363f3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 17 Apr 2015 22:57:40 +0000 Subject: -doxygen, indentation --- src/util/common_allocation.c | 141 ++++++++++++++++++++++++++++--------------- 1 file changed, 92 insertions(+), 49 deletions(-) (limited to 'src/util') diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index c31ad6253..5280d73b2 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c @@ -53,25 +53,32 @@ static LONG mem_used = 0; * memory is available. * * @param size how many bytes of memory to allocate, do NOT use - * this function (or GNUNET_malloc) to allocate more than several MB + * this function (or GNUNET_malloc()) to allocate more than several MB * of memory, if you are possibly needing a very large chunk use - * GNUNET_xmalloc_unchecked_ instead. - * @param filename where in the code was the call to GNUNET_malloc - * @param linenumber where in the code was the call to GNUNET_malloc + * #GNUNET_xmalloc_unchecked_() instead. + * @param filename where in the code was the call to GNUNET_malloc() + * @param linenumber where in the code was the call to GNUNET_malloc() * @return pointer to size bytes of memory */ void * -GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) +GNUNET_xmalloc_ (size_t size, + const char *filename, + int linenumber) { void *ret; /* As a security precaution, we generally do not allow very large - * allocations using the default 'GNUNET_malloc' macro */ - GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); - ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber); - if (ret == NULL) + * allocations using the default 'GNUNET_malloc()' macro */ + GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, + filename, + linenumber); + ret = GNUNET_xmalloc_unchecked_ (size, + filename, + linenumber); + if (NULL == ret) { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, + "malloc"); GNUNET_assert (0); } return ret; @@ -80,8 +87,8 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) /** * Allocate and initialize memory. Checks the return value, aborts if no more - * memory is available. Don't use GNUNET_xmemdup_ directly. Use the - * GNUNET_memdup macro. + * memory is available. Don't use #GNUNET_xmemdup_() directly. Use the + * GNUNET_memdup() macro. * * @param buf buffer to initialize from (must contain size bytes) * @param size number of bytes to allocate @@ -90,7 +97,9 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) * @return allocated memory, never NULL */ void * -GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, +GNUNET_xmemdup_ (const void *buf, + size_t size, + const char *filename, int linenumber) { void *ret; @@ -120,18 +129,19 @@ GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, } - /** - * Wrapper around malloc. Allocates size bytes of memory. + * Wrapper around malloc(). Allocates size bytes of memory. * The memory will be zero'ed out. * * @param size the number of bytes to allocate - * @param filename where in the code was the call to GNUNET_malloc_large - * @param linenumber where in the code was the call to GNUNET_malloc_large + * @param filename where in the code was the call to GNUNET_malloc_unchecked() + * @param linenumber where in the code was the call to GNUNET_malloc_unchecked() * @return pointer to size bytes of memory, NULL if we do not have enough memory */ void * -GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) +GNUNET_xmalloc_unchecked_ (size_t size, + const char *filename, + int linenumber) { void *result; @@ -142,7 +152,7 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) #endif result = malloc (size); - if (result == NULL) + if (NULL == result) return NULL; memset (result, 0, size); @@ -162,12 +172,15 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) * * @param ptr the pointer to reallocate * @param n how many bytes of memory to allocate - * @param filename where in the code was the call to GNUNET_realloc - * @param linenumber where in the code was the call to GNUNET_realloc + * @param filename where in the code was the call to GNUNET_realloc() + * @param linenumber where in the code was the call to GNUNET_realloc() * @return pointer to size bytes of memory */ void * -GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) +GNUNET_xrealloc_ (void *ptr, + size_t n, + const char *filename, + int linenumber) { #ifdef W32_MEM_LIMIT n += sizeof (size_t); @@ -215,9 +228,13 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) * @param linenumber where in the code was the call to GNUNET_array_grow */ void -GNUNET_xfree_ (void *ptr, const char *filename, int linenumber) +GNUNET_xfree_ (void *ptr, + const char *filename, + int linenumber) { - GNUNET_assert_at (ptr != NULL, filename, linenumber); + GNUNET_assert_at (NULL != ptr, + filename, + linenumber); #ifdef W32_MEM_LIMIT ptr = &((size_t *) ptr)[-1]; mem_used -= *((size_t *) ptr); @@ -239,22 +256,33 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber) free (ptr); } + /** * Dup a string (same semantics as strdup). * * @param str the string to dup - * @param filename where in the code was the call to GNUNET_strdup - * @param linenumber where in the code was the call to GNUNET_strdup - * @return strdup(str) + * @param filename where in the code was the call to GNUNET_strdup() + * @param linenumber where in the code was the call to GNUNET_strdup() + * @return `strdup(@a str)` */ char * -GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber) +GNUNET_xstrdup_ (const char *str, + const char *filename, + int linenumber) { char *res; - - GNUNET_assert_at (str != NULL, filename, linenumber); - res = GNUNET_xmalloc_ (strlen (str) + 1, filename, linenumber); - memcpy (res, str, strlen (str) + 1); + size_t slen; + + GNUNET_assert_at (str != NULL, + filename, + linenumber); + slen = strlen (str) + 1; + res = GNUNET_xmalloc_ (slen, + filename, + linenumber); + memcpy (res, + str, + slen); return res; } @@ -279,21 +307,28 @@ strnlen (const char *s, * * @param str the string to dup * @param len the length of the string to dup - * @param filename where in the code was the call to GNUNET_strndup - * @param linenumber where in the code was the call to GNUNET_strndup - * @return strndup(str,len) + * @param filename where in the code was the call to GNUNET_strndup() + * @param linenumber where in the code was the call to GNUNET_strndup() + * @return `strndup(@a str,@a len)` */ char * -GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, +GNUNET_xstrndup_ (const char *str, + size_t len, + const char *filename, int linenumber) { char *res; if (0 == len) return GNUNET_strdup (""); - GNUNET_assert_at (str != NULL, filename, linenumber); - len = strnlen (str, len); - res = GNUNET_xmalloc_ (len + 1, filename, linenumber); + GNUNET_assert_at (NULL != str, + filename, + linenumber); + len = strnlen (str, + len); + res = GNUNET_xmalloc_ (len + 1, + filename, + linenumber); memcpy (res, str, len); /* res[len] = '\0'; 'malloc' zeros out anyway */ return res; @@ -309,12 +344,16 @@ GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, * @param elementSize the size of the elements of the array * @param oldCount address of the number of elements in the *old array * @param newCount number of elements in the new array, may be 0 - * @param filename where in the code was the call to GNUNET_array_grow - * @param linenumber where in the code was the call to GNUNET_array_grow + * @param filename where in the code was the call to GNUNET_array_grow() + * @param linenumber where in the code was the call to GNUNET_array_grow() */ void -GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, - unsigned int newCount, const char *filename, int linenumber) +GNUNET_xgrow_ (void **old, + size_t elementSize, + unsigned int *oldCount, + unsigned int newCount, + const char *filename, + int linenumber) { void *tmp; size_t size; @@ -344,15 +383,17 @@ GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, /** - * Like asprintf, just portable. + * Like asprintf(), just portable. * * @param buf set to a buffer of sufficient size (allocated, caller must free) - * @param format format string (see printf, fprintf, etc.) + * @param format format string (see printf(), fprintf(), etc.) * @param ... data for format string - * @return number of bytes in "*buf" excluding 0-termination + * @return number of bytes in `*@a buf`, excluding 0-termination */ int -GNUNET_asprintf (char **buf, const char *format, ...) +GNUNET_asprintf (char **buf, + const char *format, + ...) { int ret; va_list args; @@ -369,7 +410,7 @@ GNUNET_asprintf (char **buf, const char *format, ...) /** - * Like snprintf, just aborts if the buffer is of insufficient size. + * Like snprintf(), just aborts if the buffer is of insufficient size. * * @param buf pointer to buffer that is written to * @param size number of bytes in buf @@ -378,7 +419,9 @@ GNUNET_asprintf (char **buf, const char *format, ...) * @return number of bytes written to buf or negative value on error */ int -GNUNET_snprintf (char *buf, size_t size, const char *format, ...) +GNUNET_snprintf (char *buf, + size_t size, + const char *format, ...) { int ret; va_list args; -- cgit v1.2.3