2021-08-07 Bruno Haible <br...@clisp.org> 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 <stdlib.h>. (u8_strdup, u16_strdup, u32_strdup): Declare that deallocation must happen through 'free'.
diff --git a/lib/uninorm.in.h b/lib/uninorm.in.h index 7c06911..d87ae27 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 ed65777..3b38207 100644 --- a/lib/unistr.in.h +++ b/lib/unistr.in.h @@ -25,6 +25,9 @@ /* Get size_t, ptrdiff_t. */ #include <stddef.h> +/* Get free(). */ +#include <stdlib.h> + #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(). */