>From 101b9d7f82f73fac4da98d26af461e975eeafd00 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 5 Nov 2024 21:11:33 +0100 Subject: [PATCH 18/23] wcsncat: Guarantee N3322 functionality. * lib/wchar.in.h (wcsncat): Consider REPLACE_WCSNCAT. * m4/wcsncat.m4 (gl_FUNC_WCSNCAT): Test whether the zero-length bug is present. * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSNCAT. * modules/wchar (Makefile.am): Substitute REPLACE_WCSNCAT. * modules/wcsncat (Status, Notice): Remove. (configure.ac): Consider REPLACE_WCSNCAT. * doc/posix-functions/wcsncat.texi: Mention the zero-length bug. --- ChangeLog | 12 ++++++++++++ doc/posix-functions/wcsncat.texi | 4 ++++ lib/wchar.in.h | 17 ++++++++++++++-- m4/wchar_h.m4 | 3 ++- m4/wcsncat.m4 | 33 ++++++++++++++++++++++++++++++-- modules/wchar | 1 + modules/wcsncat | 9 ++------- 7 files changed, 67 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5f1a392fb4..c019e77f02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2024-11-05 Bruno Haible + + wcsncat: Guarantee N3322 functionality. + * lib/wchar.in.h (wcsncat): Consider REPLACE_WCSNCAT. + * m4/wcsncat.m4 (gl_FUNC_WCSNCAT): Test whether the zero-length bug is + present. + * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSNCAT. + * modules/wchar (Makefile.am): Substitute REPLACE_WCSNCAT. + * modules/wcsncat (Status, Notice): Remove. + (configure.ac): Consider REPLACE_WCSNCAT. + * doc/posix-functions/wcsncat.texi: Mention the zero-length bug. + 2024-11-05 Bruno Haible wmemmove tests: Verify N3322 functionality. diff --git a/doc/posix-functions/wcsncat.texi b/doc/posix-functions/wcsncat.texi index 70232aa30e..28cbe049f4 100644 --- a/doc/posix-functions/wcsncat.texi +++ b/doc/posix-functions/wcsncat.texi @@ -9,6 +9,10 @@ Portability problems fixed by Gnulib: @itemize +@item +This function does not support zero-length operations on NULL pointers +on some platforms: +macOS 15, NetBSD 10.0, OpenBSD 7.6, Solaris 11.4, Cygwin 3.5.4. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 54354559ef..3c6beb0712 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -1149,14 +1149,27 @@ _GL_WARN_ON_USE (wcscat, "wcscat is unportable - " /* Append no more than N wide characters of SRC onto DEST. */ #if @GNULIB_WCSNCAT@ -# if !@HAVE_WCSNCAT@ +# if @REPLACE_WCSNCAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcsncat +# define wcsncat rpl_wcsncat +# endif +_GL_FUNCDECL_RPL (wcsncat, wchar_t *, + (wchar_t *restrict dest, const wchar_t *restrict src, + size_t n), ); +_GL_CXXALIAS_RPL (wcsncat, wchar_t *, + (wchar_t *restrict dest, const wchar_t *restrict src, + size_t n)); +# else +# if !@HAVE_WCSNCAT@ _GL_FUNCDECL_SYS (wcsncat, wchar_t *, (wchar_t *restrict dest, const wchar_t *restrict src, size_t n), ); -# endif +# endif _GL_CXXALIAS_SYS (wcsncat, wchar_t *, (wchar_t *restrict dest, const wchar_t *restrict src, size_t n)); +# endif # if __GLIBC__ >= 2 _GL_CXXALIASWARN (wcsncat); # endif diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index 14296d0291..cba48b3dc9 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -1,5 +1,5 @@ # wchar_h.m4 -# serial 64 +# serial 65 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -257,6 +257,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS] REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH]) REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME]) REPLACE_WCSCMP=0; AC_SUBST([REPLACE_WCSCMP]) + REPLACE_WCSNCAT=0; AC_SUBST([REPLACE_WCSNCAT]) REPLACE_WCSNCMP=0; AC_SUBST([REPLACE_WCSNCMP]) REPLACE_WCSSTR=0; AC_SUBST([REPLACE_WCSSTR]) REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK]) diff --git a/m4/wcsncat.m4 b/m4/wcsncat.m4 index 13dbe354a5..7b04f23c95 100644 --- a/m4/wcsncat.m4 +++ b/m4/wcsncat.m4 @@ -1,5 +1,5 @@ # wcsncat.m4 -# serial 2 +# serial 3 dnl Copyright (C) 2011-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,8 +9,37 @@ AC_DEFUN([gl_FUNC_WCSNCAT], [ AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CHECK_FUNCS_ONCE([wcsncat]) - if test $ac_cv_func_wcsncat = no; then + if test $ac_cv_func_wcsncat = yes; then + AC_CACHE_CHECK([for working wcsncat], [gl_cv_func_wcsncat_works], + [AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include + #include + ]], [[ + wchar_t y[1]; + int volatile value = (wcsncat (y, NULL, 0) == y); + return !value; + ]]) + ], + [gl_cv_func_wcsncat_works=yes], + [gl_cv_func_wcsncat_works=no], + [case "$host_os" in + # Guess no on macOS, NetBSD, OpenBSD, Solaris, Cygwin. + darwin* | netbsd* | openbsd* | solaris* | cygwin*) + gl_cv_func_wcsncat_works="guessing no" ;; + *) + gl_cv_func_strndup_works="guessing yes" ;; + esac + ]) + ]) + case "$gl_cv_func_wcsncat_works" in + *yes) ;; + *) REPLACE_WCSNCAT=1 ;; + esac + else HAVE_WCSNCAT=0 fi ]) diff --git a/modules/wchar b/modules/wchar index 393b2b1837..ac2ce394a3 100644 --- a/modules/wchar +++ b/modules/wchar @@ -148,6 +148,7 @@ wchar.h: wchar.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \ -e 's|@''REPLACE_WCSFTIME''@|$(REPLACE_WCSFTIME)|g' \ -e 's|@''REPLACE_WCSCMP''@|$(REPLACE_WCSCMP)|g' \ + -e 's|@''REPLACE_WCSNCAT''@|$(REPLACE_WCSNCAT)|g' \ -e 's|@''REPLACE_WCSNCMP''@|$(REPLACE_WCSNCMP)|g' \ -e 's|@''REPLACE_WCSSTR''@|$(REPLACE_WCSSTR)|g' \ -e 's|@''REPLACE_WCSTOK''@|$(REPLACE_WCSTOK)|g' \ diff --git a/modules/wcsncat b/modules/wcsncat index 354e317616..86708e543e 100644 --- a/modules/wcsncat +++ b/modules/wcsncat @@ -1,12 +1,6 @@ Description: wcsncat() function: append part of a wide string to a wide string. -Status: -obsolete - -Notice: -This module is obsolete. - Files: lib/wcsncat.c lib/wcsncat-impl.h @@ -17,7 +11,8 @@ wchar configure.ac: gl_FUNC_WCSNCAT -gl_CONDITIONAL([GL_COND_OBJ_WCSNCAT], [test $HAVE_WCSNCAT = 0]) +gl_CONDITIONAL([GL_COND_OBJ_WCSNCAT], + [test $HAVE_WCSNCAT = 0 || test $REPLACE_WCSNCAT = 1]) gl_WCHAR_MODULE_INDICATOR([wcsncat]) Makefile.am: -- 2.34.1