From d3c1eca926275d7138cdfd2eaebcf5de472fcdbf Mon Sep 17 00:00:00 2001 From: Bruno Haible <bruno@clisp.org> Date: Sat, 7 Aug 2021 23:15:21 +0200 Subject: [PATCH] xstrndup: Improve GCC 11 allocation-deallocation checking. * lib/xstrndup.h: Include <stdlib.h> instead of <stddef.h>. (xstrndup): Declare that deallocation must happen through 'free'. --- ChangeLog | 6 ++++++ lib/xstrndup.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7dccacbb46..8e3707f046 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-08-07 Bruno Haible <bruno@clisp.org> + + xstrndup: Improve GCC 11 allocation-deallocation checking. + * lib/xstrndup.h: Include <stdlib.h> instead of <stddef.h>. + (xstrndup): Declare that deallocation must happen through 'free'. + 2021-08-07 Bruno Haible <bruno@clisp.org> xstriconveh: Improve GCC 11 allocation-deallocation checking. diff --git a/lib/xstrndup.h b/lib/xstrndup.h index 7fbbf2c1b9..dc4f6e273e 100644 --- a/lib/xstrndup.h +++ b/lib/xstrndup.h @@ -15,9 +15,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include <stddef.h> +#include <stdlib.h> /* Return a newly allocated copy of at most N bytes of STRING. In other words, return a copy of the initial segment of length N of STRING. */ -extern char *xstrndup (const char *string, size_t n) _GL_ATTRIBUTE_MALLOC; +extern char *xstrndup (const char *string, size_t n) + _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE + _GL_ATTRIBUTE_RETURNS_NONNULL; -- 2.39.5