From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2206) id BF8923994821; Wed, 28 Jul 2021 12:18:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BF8923994821 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Siddhesh Poyarekar To: glibc-cvs@sourceware.org Subject: [glibc] tests: use xmalloc to allocate implementation array X-Act-Checkin: glibc X-Git-Author: Siddhesh Poyarekar X-Git-Refname: refs/heads/master X-Git-Oldrev: b8e8bb324a376cd99bb61b6c21f63c395cae9b5d X-Git-Newrev: 70d08ba2046f4e589fdfa0f35999dfd413844bef Message-Id: <20210728121801.BF8923994821@sourceware.org> Date: Wed, 28 Jul 2021 12:18:01 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jul 2021 12:18:01 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=70d08ba2046f4e589fdfa0f35999dfd413844bef commit 70d08ba2046f4e589fdfa0f35999dfd413844bef Author: Siddhesh Poyarekar Date: Wed Jul 28 13:03:27 2021 +0530 tests: use xmalloc to allocate implementation array The benchmark and tests must fail in case of allocation failure in the implementation array. Also annotate the x* allocators in support.h so that the compiler has more information about them. Reviewed-by: Florian Weimer Diff: --- benchtests/bench-string.h | 5 +++-- string/test-string.h | 5 +++-- support/support.h | 24 +++++++++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/benchtests/bench-string.h b/benchtests/bench-string.h index fd25264417..12f27473ff 100644 --- a/benchtests/bench-string.h +++ b/benchtests/bench-string.h @@ -18,6 +18,7 @@ #include #include +#include /* We are compiled under _ISOMAC, so libc-symbols.h does not do this for us. */ @@ -200,8 +201,8 @@ static impl_t *impl_array; skip = impl; \ else \ impl_count++; \ - a = impl_array = malloc ((impl_count + func_count) * \ - sizeof (impl_t)); \ + a = impl_array = xmalloc ((impl_count + func_count) * \ + sizeof (impl_t)); \ for (impl = __start_impls; impl < __stop_impls; ++impl) \ if (impl != skip) \ *a++ = *impl; \ diff --git a/string/test-string.h b/string/test-string.h index febde61040..78b66efe36 100644 --- a/string/test-string.h +++ b/string/test-string.h @@ -18,6 +18,7 @@ . */ #include +#include typedef struct { @@ -146,8 +147,8 @@ static impl_t *impl_array; skip = impl; \ else \ impl_count++; \ - a = impl_array = malloc ((impl_count + func_count) * \ - sizeof (impl_t)); \ + a = impl_array = xmalloc ((impl_count + func_count) * \ + sizeof (impl_t)); \ for (impl = __start_impls; impl < __stop_impls; ++impl) \ if (impl != skip) \ *a++ = *impl; \ diff --git a/support/support.h b/support/support.h index dbd270c78d..834dba9097 100644 --- a/support/support.h +++ b/support/support.h @@ -87,14 +87,24 @@ int support_descriptor_supports_holes (int fd); /* Error-checking wrapper functions which terminate the process on error. */ -void *xmalloc (size_t) __attribute__ ((malloc)); -void *xcalloc (size_t n, size_t s) __attribute__ ((malloc)); -void *xrealloc (void *p, size_t n); -void *xposix_memalign (size_t alignment, size_t n); +extern void *xmalloc (size_t n) + __attribute_malloc__ __attribute_alloc_size__ ((1)) __attr_dealloc_free + __returns_nonnull; +extern void *xcalloc (size_t n, size_t s) + __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __attr_dealloc_free + __returns_nonnull; +extern void *xrealloc (void *o, size_t n) + __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free; +extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free + __returns_nonnull; +void *xposix_memalign (size_t alignment, size_t n) + __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free + __returns_nonnull; char *xasprintf (const char *format, ...) - __attribute__ ((format (printf, 1, 2), malloc)); -char *xstrdup (const char *); -char *xstrndup (const char *, size_t); + __attribute__ ((format (printf, 1, 2), malloc)) __attr_dealloc_free + __returns_nonnull; +char *xstrdup (const char *) __attr_dealloc_free __returns_nonnull; +char *xstrndup (const char *, size_t) __attr_dealloc_free __returns_nonnull; char *xsetlocale (int category, const char *locale); locale_t xnewlocale (int category_mask, const char *locale, locale_t base); char *xuselocale (locale_t newloc);