From 526cd383bd18ea29e390548cfde68e2d6d7fa5f9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 8 Aug 2021 02:14:11 +0200 Subject: [PATCH] uninorm, unistr: Improve GCC 11 allocation-deallocation checking. * lib/uninorm.in.h (uninorm_filter_free): Move declaration up. (uninorm_filter_create): Declare that deallocation must happen through 'uninorm_filter_free'. * lib/unistr.in.h: Include . (u8_strdup, u16_strdup, u32_strdup): Declare that deallocation must happen through 'free'. --- ChangeLog | 10 ++++++++++ lib/uninorm.in.h | 15 ++++++++------- lib/unistr.in.h | 12 +++++++++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0355389b85..b185a305c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2021-08-07 Bruno Haible + + uninorm, unistr: Improve GCC 11 allocation-deallocation checking. + * lib/uninorm.in.h (uninorm_filter_free): Move declaration up. + (uninorm_filter_create): Declare that deallocation must happen through + 'uninorm_filter_free'. + * lib/unistr.in.h: Include . + (u8_strdup, u16_strdup, u32_strdup): Declare that deallocation must + happen through 'free'. + 2021-08-07 Bruno Haible ialloc: Prepare for allocation-deallocation checking. diff --git a/lib/uninorm.in.h b/lib/uninorm.in.h index 7c0691127c..d87ae27518 100644 --- a/lib/uninorm.in.h +++ b/lib/uninorm.in.h @@ -209,6 +209,12 @@ extern int sequence to the encapsulated stream of Unicode characters. */ struct uninorm_filter; +/* Bring data buffered in the filter to its destination, the encapsulated + stream, then close and free the filter. + Return 0 if successful, or -1 with errno set upon failure. */ +extern int + uninorm_filter_free (struct uninorm_filter *filter); + /* Create and return a normalization filter for Unicode characters. The pair (stream_func, stream_data) is the encapsulated stream. stream_func (stream_data, uc) receives the Unicode character uc @@ -217,7 +223,8 @@ struct uninorm_filter; extern struct uninorm_filter * uninorm_filter_create (uninorm_t nf, int (*stream_func) (void *stream_data, ucs4_t uc), - void *stream_data); + void *stream_data) + _GL_ATTRIBUTE_DEALLOC (uninorm_filter_free, 1); /* Stuff a Unicode character into a normalizing filter. Return 0 if successful, or -1 with errno set upon failure. */ @@ -233,12 +240,6 @@ extern int extern int uninorm_filter_flush (struct uninorm_filter *filter); -/* Bring data buffered in the filter to its destination, the encapsulated - stream, then close and free the filter. - Return 0 if successful, or -1 with errno set upon failure. */ -extern int - uninorm_filter_free (struct uninorm_filter *filter); - #ifdef __cplusplus } diff --git a/lib/unistr.in.h b/lib/unistr.in.h index ed657773c4..3b38207f90 100644 --- a/lib/unistr.in.h +++ b/lib/unistr.in.h @@ -25,6 +25,9 @@ /* Get size_t, ptrdiff_t. */ #include +/* Get free(). */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -624,11 +627,14 @@ extern int /* Duplicate S, returning an identical malloc'd string. */ /* Similar to strdup(), wcsdup(). */ extern uint8_t * - u8_strdup (const uint8_t *s); + u8_strdup (const uint8_t *s) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE; extern uint16_t * - u16_strdup (const uint16_t *s); + u16_strdup (const uint16_t *s) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE; extern uint32_t * - u32_strdup (const uint32_t *s); + u32_strdup (const uint32_t *s) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE; /* Find the first occurrence of UC in STR. */ /* Similar to strchr(), wcschr(). */ -- 2.39.5