Paul Eggert wrote in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-10/msg00032.html>:

> Yes, it was accepted by WG14 last week. See:
>
> https://sourceware.org/pipermail/libc-alpha/2024-October/160375.html

While Gnulib cannot do anything for the NULL + 0 and NULL - NULL expressions
(these need to be fixed in the compilers), Gnulib can help for the function
calls.

Here are patches that verify the Gnulib requirements for the cited functions.
For two of them (strndup and wcsncat) I had to add workarounds for specific
functions.

Other than that, test failures only happen with the undefined-behaviour
sanitizer.

* With CC="gcc -fsanitize=undefined -fno-sanitize-recover=undefined":
FAIL: test-bsearch
FAIL: test-memccpy
FAIL: test-memcpy
FAIL: test-memmove
FAIL: test-memset
FAIL: test-memset_explicit
FAIL: test-qsort
FAIL: test-strncat
FAIL: test-strncpy
FAIL: test-strndup
FAIL: test-wcsncmp
FAIL: test-wcsncpy

* With CC="clang -fsanitize=undefined -fno-sanitize-recover=undefined":
FAIL: test-bsearch
FAIL: test-memccpy
FAIL: test-memchr
FAIL: test-memcpy
FAIL: test-memmove
FAIL: test-memset
FAIL: test-memset_explicit
FAIL: test-qsort
FAIL: test-strncat
FAIL: test-strncpy
FAIL: test-strndup
FAIL: test-wcsncpy

I don't think it's worth adding workarounds for these test failures, because
  - Building with sanitizer and -fno-sanitize-recover=... is not the usual way
    of building programs.
  - Bug reports for glibc, gcc, clang are already registered.

Bruno


2024-11-05  Bruno Haible  <br...@clisp.org>

        wmemset tests: Verify N3322 functionality.
        * tests/test-wmemset.c: New file.
        * modules/wmemset-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        wmemchr tests: Verify N3322 functionality.
        * tests/test-wmemchr.c: New file.
        * modules/wmemchr-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        wmemcmp tests: Verify N3322 functionality.
        * tests/test-wmemcmp.c (main): Add zero-size tests.

2024-11-05  Bruno Haible  <br...@clisp.org>

        wcsncmp tests: Verify N3322 functionality.
        * tests/test-wcsncmp.c (main): Add zero-size tests.

2024-11-05  Bruno Haible  <br...@clisp.org>

        wcsncat tests: Verify N3322 functionality.
        * tests/test-wcsncat.c: New file.
        * modules/wcsncat-tests: New file.

        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  <br...@clisp.org>

        wmemmove tests: Verify N3322 functionality.
        * tests/test-wmemmove.c: New file.
        * modules/wmemmove-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        wmemcpy tests: Verify N3322 functionality.
        * tests/test-wmemcpy.c: New file.
        * modules/wmemcpy-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        wcsncpy tests: Verify N3322 functionality.
        * tests/test-wcsncpy.c: New file.
        * modules/wcsncpy-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        memset_explicit tests: Verify N3322 functionality.
        * tests/test-memset_explicit.c (main): Add a zero-size test.

2024-11-05  Bruno Haible  <br...@clisp.org>

        memset tests: Verify N3322 functionality.
        * tests/test-memset.c: New file.
        * modules/memset-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        memchr tests: Verify N3322 functionality.
        * tests/test-memchr.c (main): Add a zero-size test.

2024-11-05  Bruno Haible  <br...@clisp.org>

        strncmp tests: Verify N3322 functionality.
        * modules/strncmp: New file.
        * doc/posix-functions/strncmp.texi: Mention the new module.
        * tests/test-strncmp.c: New file.
        * modules/strncmp-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        memcmp tests: Verify N3322 functionality.
        * tests/test-memcmp.c (main): Add zero-size tests.

2024-11-05  Bruno Haible  <br...@clisp.org>

        strncat tests: Verify N3322 functionality.
        * tests/test-strncat.c (main): Add a zero-size test.

2024-11-05  Bruno Haible  <br...@clisp.org>

        strndup tests: Verify N3322 functionality.
        * tests/test-strndup.c: New file.
        * modules/strndup-tests: New file.

        strndup: Guarantee N3322 functionality.
        * m4/strndup.m4 (gl_FUNC_STRNDUP): Check against the AIX bug.
        * doc/posix-functions/strndup.texi: Mention the AIX bug.

2024-11-05  Bruno Haible  <br...@clisp.org>

        strncpy tests: Verify N3322 functionality.
        * modules/strncpy: New file.
        * doc/posix-functions/strncpy.texi: Mention the new module.
        * tests/test-strncpy.c: New file.
        * modules/strncpy-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        memmove tests: Verify N3322 functionality.
        * tests/test-memmove.c: New file.
        * modules/memmove-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        memccpy tests: Verify N3322 functionality.
        * modules/memccpy: New file.
        * doc/posix-functions/memccpy.texi: Mention the new module.
        * tests/test-memccpy.c: New file.
        * modules/memccpy-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        memcpy tests: Verify N3322 functionality.
        * tests/test-memcpy.c: New file.
        * modules/memcpy-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        qsort tests: Verify N3322 functionality.
        * modules/qsort: New file.
        * doc/posix-functions/qsort.texi: Mention the new module.
        * tests/test-qsort.c: New file.
        * modules/qsort-tests: New file.

2024-11-05  Bruno Haible  <br...@clisp.org>

        bsearch tests: Verify N3322 functionality.
        * modules/bsearch: New file.
        * doc/posix-functions/bsearch.texi: Mention the new module.
        * tests/test-bsearch.c: New file.
        * modules/bsearch-tests: New file.

>From bc91828e1825baffcb35ad8032c52ca632b57ffa Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:09:07 +0100
Subject: [PATCH 01/23] bsearch tests: Verify N3322 functionality.

* modules/bsearch: New file.
* doc/posix-functions/bsearch.texi: Mention the new module.
* tests/test-bsearch.c: New file.
* modules/bsearch-tests: New file.
---
 ChangeLog                        |  8 ++++++
 doc/posix-functions/bsearch.texi |  3 ++-
 modules/bsearch                  | 25 +++++++++++++++++++
 modules/bsearch-tests            | 11 +++++++++
 tests/test-bsearch.c             | 42 ++++++++++++++++++++++++++++++++
 5 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 modules/bsearch
 create mode 100644 modules/bsearch-tests
 create mode 100644 tests/test-bsearch.c

diff --git a/ChangeLog b/ChangeLog
index c3e15d31d4..55cbc80e0f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	bsearch tests: Verify N3322 functionality.
+	* modules/bsearch: New file.
+	* doc/posix-functions/bsearch.texi: Mention the new module.
+	* tests/test-bsearch.c: New file.
+	* modules/bsearch-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	realloc-posix: Avoid use of AC_LIBOBJ.
diff --git a/doc/posix-functions/bsearch.texi b/doc/posix-functions/bsearch.texi
index 1ec4e9351b..96c41f6db6 100644
--- a/doc/posix-functions/bsearch.texi
+++ b/doc/posix-functions/bsearch.texi
@@ -4,7 +4,8 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/bsearch.html}
 
-Gnulib module: ---
+Gnulib module: bsearch
+@mindex bsearch
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/modules/bsearch b/modules/bsearch
new file mode 100644
index 0000000000..596217291f
--- /dev/null
+++ b/modules/bsearch
@@ -0,0 +1,25 @@
+Description:
+Binary search in a sorted array.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/bsearch-tests b/modules/bsearch-tests
new file mode 100644
index 0000000000..81a1c15e4a
--- /dev/null
+++ b/modules/bsearch-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-bsearch.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-bsearch
+check_PROGRAMS += test-bsearch
diff --git a/tests/test-bsearch.c b/tests/test-bsearch.c
new file mode 100644
index 0000000000..8d62dc3e20
--- /dev/null
+++ b/tests/test-bsearch.c
@@ -0,0 +1,42 @@
+/* Test of bsearch() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <stdlib.h>
+
+#include "macros.h"
+
+static int
+cmp (const void *a, const void *b)
+{
+  return 0;
+}
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (bsearch ("x", NULL, 0, 1, cmp) == NULL);
+  ASSERT (value);
+
+  return test_exit_status;
+}
-- 
2.34.1

>From d3c9d629b8eadfda54c16879b36b7edfd2f03805 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:10:02 +0100
Subject: [PATCH 02/23] qsort tests: Verify N3322 functionality.

* modules/qsort: New file.
* doc/posix-functions/qsort.texi: Mention the new module.
* tests/test-qsort.c: New file.
* modules/qsort-tests: New file.
---
 ChangeLog                      |  8 ++++++++
 doc/posix-functions/qsort.texi |  3 ++-
 modules/qsort                  | 25 +++++++++++++++++++++++
 modules/qsort-tests            | 10 +++++++++
 tests/test-qsort.c             | 37 ++++++++++++++++++++++++++++++++++
 5 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 modules/qsort
 create mode 100644 modules/qsort-tests
 create mode 100644 tests/test-qsort.c

diff --git a/ChangeLog b/ChangeLog
index 55cbc80e0f..59575ece66 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	qsort tests: Verify N3322 functionality.
+	* modules/qsort: New file.
+	* doc/posix-functions/qsort.texi: Mention the new module.
+	* tests/test-qsort.c: New file.
+	* modules/qsort-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	bsearch tests: Verify N3322 functionality.
diff --git a/doc/posix-functions/qsort.texi b/doc/posix-functions/qsort.texi
index 5d6523e528..87491b7eeb 100644
--- a/doc/posix-functions/qsort.texi
+++ b/doc/posix-functions/qsort.texi
@@ -4,7 +4,8 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/qsort.html}
 
-Gnulib module: ---
+Gnulib module: qsort
+@mindex qsort
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/modules/qsort b/modules/qsort
new file mode 100644
index 0000000000..8fef487959
--- /dev/null
+++ b/modules/qsort
@@ -0,0 +1,25 @@
+Description:
+Sorting an array.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/qsort-tests b/modules/qsort-tests
new file mode 100644
index 0000000000..6d31f6b09e
--- /dev/null
+++ b/modules/qsort-tests
@@ -0,0 +1,10 @@
+Files:
+tests/test-qsort.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-qsort
+check_PROGRAMS += test-qsort
diff --git a/tests/test-qsort.c b/tests/test-qsort.c
new file mode 100644
index 0000000000..9ab39b13e4
--- /dev/null
+++ b/tests/test-qsort.c
@@ -0,0 +1,37 @@
+/* Test of qsort() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <stdlib.h>
+
+static int
+cmp (const void *a, const void *b)
+{
+  return 0;
+}
+
+int
+main (void)
+{
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  qsort (NULL, 0, 1, cmp);
+
+  return 0;
+}
-- 
2.34.1

>From bec3105627f033544fd373db2bc657c73197aec6 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:10:05 +0100
Subject: [PATCH 03/23] memcpy tests: Verify N3322 functionality.

* tests/test-memcpy.c: New file.
* modules/memcpy-tests: New file.
---
 ChangeLog            |  6 ++++++
 modules/memcpy-tests | 11 +++++++++++
 tests/test-memcpy.c  | 44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 modules/memcpy-tests
 create mode 100644 tests/test-memcpy.c

diff --git a/ChangeLog b/ChangeLog
index 59575ece66..3628942415 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	memcpy tests: Verify N3322 functionality.
+	* tests/test-memcpy.c: New file.
+	* modules/memcpy-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	qsort tests: Verify N3322 functionality.
diff --git a/modules/memcpy-tests b/modules/memcpy-tests
new file mode 100644
index 0000000000..e54782b4d2
--- /dev/null
+++ b/modules/memcpy-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-memcpy.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-memcpy
+check_PROGRAMS += test-memcpy
diff --git a/tests/test-memcpy.c b/tests/test-memcpy.c
new file mode 100644
index 0000000000..a0292ea719
--- /dev/null
+++ b/tests/test-memcpy.c
@@ -0,0 +1,44 @@
+/* Test of memcpy() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (memcpy (NULL, "x", 0) == NULL);
+  ASSERT (value);
+
+  {
+    char y[1];
+    value = (memcpy (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From bda6e6a07764e0ece7e9f7869d40ae4daed10e28 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:10:08 +0100
Subject: [PATCH 04/23] memccpy tests: Verify N3322 functionality.

* modules/memccpy: New file.
* doc/posix-functions/memccpy.texi: Mention the new module.
* tests/test-memccpy.c: New file.
* modules/memccpy-tests: New file.
---
 ChangeLog                        |  8 ++++++
 doc/posix-functions/memccpy.texi |  3 ++-
 modules/memccpy                  | 25 ++++++++++++++++++
 modules/memccpy-tests            | 11 ++++++++
 tests/test-memccpy.c             | 44 ++++++++++++++++++++++++++++++++
 5 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 modules/memccpy
 create mode 100644 modules/memccpy-tests
 create mode 100644 tests/test-memccpy.c

diff --git a/ChangeLog b/ChangeLog
index 3628942415..4e9afd8098 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	memccpy tests: Verify N3322 functionality.
+	* modules/memccpy: New file.
+	* doc/posix-functions/memccpy.texi: Mention the new module.
+	* tests/test-memccpy.c: New file.
+	* modules/memccpy-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	memcpy tests: Verify N3322 functionality.
diff --git a/doc/posix-functions/memccpy.texi b/doc/posix-functions/memccpy.texi
index 7761aca6a8..becefb1a03 100644
--- a/doc/posix-functions/memccpy.texi
+++ b/doc/posix-functions/memccpy.texi
@@ -4,7 +4,8 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/memccpy.html}
 
-Gnulib module: ---
+Gnulib module: memccpy
+@mindex memccpy
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/modules/memccpy b/modules/memccpy
new file mode 100644
index 0000000000..4c3a773c97
--- /dev/null
+++ b/modules/memccpy
@@ -0,0 +1,25 @@
+Description:
+Copy delimited memory area.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/memccpy-tests b/modules/memccpy-tests
new file mode 100644
index 0000000000..0a09402ba7
--- /dev/null
+++ b/modules/memccpy-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-memccpy.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-memccpy
+check_PROGRAMS += test-memccpy
diff --git a/tests/test-memccpy.c b/tests/test-memccpy.c
new file mode 100644
index 0000000000..576748dad8
--- /dev/null
+++ b/tests/test-memccpy.c
@@ -0,0 +1,44 @@
+/* Test of memccpy() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (memccpy (NULL, "x", '?', 0) == NULL);
+  ASSERT (value);
+
+  {
+    char y[1];
+    value = (memccpy (y, NULL, '?', 0) == NULL);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From df58cd949426ad374205973a63bb0396ffa12b7b Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:10:11 +0100
Subject: [PATCH 05/23] memmove tests: Verify N3322 functionality.

* tests/test-memmove.c: New file.
* modules/memmove-tests: New file.
---
 ChangeLog             |  6 ++++++
 modules/memmove-tests | 11 +++++++++++
 tests/test-memmove.c  | 44 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 modules/memmove-tests
 create mode 100644 tests/test-memmove.c

diff --git a/ChangeLog b/ChangeLog
index 4e9afd8098..a8fde5dfbc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	memmove tests: Verify N3322 functionality.
+	* tests/test-memmove.c: New file.
+	* modules/memmove-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	memccpy tests: Verify N3322 functionality.
diff --git a/modules/memmove-tests b/modules/memmove-tests
new file mode 100644
index 0000000000..8a04e9afd4
--- /dev/null
+++ b/modules/memmove-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-memmove.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-memmove
+check_PROGRAMS += test-memmove
diff --git a/tests/test-memmove.c b/tests/test-memmove.c
new file mode 100644
index 0000000000..ffc24622b2
--- /dev/null
+++ b/tests/test-memmove.c
@@ -0,0 +1,44 @@
+/* Test of memmove() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (memmove (NULL, "x", 0) == NULL);
+  ASSERT (value);
+
+  {
+    char y[1];
+    value = (memmove (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From 2590ea7fe1aebd71ce37e611b5096a160b633344 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:10:13 +0100
Subject: [PATCH 06/23] strncpy tests: Verify N3322 functionality.

* modules/strncpy: New file.
* doc/posix-functions/strncpy.texi: Mention the new module.
* tests/test-strncpy.c: New file.
* modules/strncpy-tests: New file.
---
 ChangeLog                        |  8 ++++++
 doc/posix-functions/strncpy.texi |  5 ++--
 modules/strncpy                  | 26 +++++++++++++++++++
 modules/strncpy-tests            | 11 ++++++++
 tests/test-strncpy.c             | 44 ++++++++++++++++++++++++++++++++
 5 files changed, 92 insertions(+), 2 deletions(-)
 create mode 100644 modules/strncpy
 create mode 100644 modules/strncpy-tests
 create mode 100644 tests/test-strncpy.c

diff --git a/ChangeLog b/ChangeLog
index a8fde5dfbc..d0514e69b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	strncpy tests: Verify N3322 functionality.
+	* modules/strncpy: New file.
+	* doc/posix-functions/strncpy.texi: Mention the new module.
+	* tests/test-strncpy.c: New file.
+	* modules/strncpy-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	memmove tests: Verify N3322 functionality.
diff --git a/doc/posix-functions/strncpy.texi b/doc/posix-functions/strncpy.texi
index 343ff249a9..ea5f41dcce 100644
--- a/doc/posix-functions/strncpy.texi
+++ b/doc/posix-functions/strncpy.texi
@@ -4,10 +4,11 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncpy.html}
 
-Gnulib module: string
+Gnulib module: string or strncpy
 @mindex string
+@mindex strncpy
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by Gnulib module @code{string} or Gnulib module @code{strncpy}:
 @itemize
 @item
 This function cannot be called from plain inline or extern inline functions
diff --git a/modules/strncpy b/modules/strncpy
new file mode 100644
index 0000000000..de91ffde5e
--- /dev/null
+++ b/modules/strncpy
@@ -0,0 +1,26 @@
+Description:
+Copy the initial part of a string.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+string
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/strncpy-tests b/modules/strncpy-tests
new file mode 100644
index 0000000000..c21d2ac3fd
--- /dev/null
+++ b/modules/strncpy-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-strncpy.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strncpy
+check_PROGRAMS += test-strncpy
diff --git a/tests/test-strncpy.c b/tests/test-strncpy.c
new file mode 100644
index 0000000000..518b43d226
--- /dev/null
+++ b/tests/test-strncpy.c
@@ -0,0 +1,44 @@
+/* Test of strncpy() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (strncpy (NULL, "x", 0) == NULL);
+  ASSERT (value);
+
+  {
+    char y[1];
+    value = (strncpy (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From bf799ba1fb48d9706aa7aa6138604a07577d8a61 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:10:20 +0100
Subject: [PATCH 07/23] strndup: Guarantee N3322 functionality.

* m4/strndup.m4 (gl_FUNC_STRNDUP): Check against the AIX bug.
* doc/posix-functions/strndup.texi: Mention the AIX bug.
---
 ChangeLog                        |  6 ++++++
 doc/posix-functions/strndup.texi |  4 ++++
 m4/strndup.m4                    | 32 +++++++++++++++++---------------
 3 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d0514e69b0..06ccb74f9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	strndup: Guarantee N3322 functionality.
+	* m4/strndup.m4 (gl_FUNC_STRNDUP): Check against the AIX bug.
+	* doc/posix-functions/strndup.texi: Mention the AIX bug.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	strncpy tests: Verify N3322 functionality.
diff --git a/doc/posix-functions/strndup.texi b/doc/posix-functions/strndup.texi
index 556e0602f1..4baabe2f5b 100644
--- a/doc/posix-functions/strndup.texi
+++ b/doc/posix-functions/strndup.texi
@@ -15,6 +15,10 @@
 @item
 This function does not NUL-terminate the result on some platforms:
 AIX 5.1.
+@item
+This function does not support zero-length operations on NULL pointers
+on some platforms:
+AIX 7.3.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/m4/strndup.m4 b/m4/strndup.m4
index 7e5aa08698..9c8b212fdd 100644
--- a/m4/strndup.m4
+++ b/m4/strndup.m4
@@ -1,5 +1,5 @@
 # strndup.m4
-# serial 23
+# serial 24
 dnl Copyright (C) 2002-2003, 2005-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,
@@ -21,7 +21,8 @@ AC_DEFUN([gl_FUNC_STRNDUP]
 
   if test $ac_cv_func_strndup = yes; then
     HAVE_STRNDUP=1
-    # AIX 4.3.3, AIX 5.1 have a function that fails to add the terminating '\0'.
+    dnl AIX 5.1 has a function that fails to add the terminating '\0'.
+    dnl AIX 7.3 has a function that does not support a zero length.
     AC_CACHE_CHECK([for working strndup], [gl_cv_func_strndup_works],
       [AC_RUN_IFELSE([
          AC_LANG_PROGRAM([[#include <string.h>
@@ -33,23 +34,24 @@ AC_DEFUN([gl_FUNC_STRNDUP]
   #endif
   char *strndup (const char *, size_t);
 #endif
-  int result;
-  char *s;
-  s = strndup ("some longer string", 15);
-  free (s);
-  s = strndup ("shorter string", 13);
-  result = s[13] != '\0';
-  free (s);
+  int result = 0;
+  {
+    char *s = strndup ("some longer string", 15);
+    free (s);
+    s = strndup ("shorter string", 13);
+    if (s[13] != '\0')
+      result |= 1;
+    free (s);
+  }
+  if (strndup (NULL, 0) == NULL)
+    result |= 2;
   return result;]])],
          [gl_cv_func_strndup_works=yes],
          [gl_cv_func_strndup_works=no],
-         [
-changequote(,)dnl
-          case $host_os in
-            aix | aix[3-6]*) gl_cv_func_strndup_works="guessing no";;
-            *)               gl_cv_func_strndup_works="guessing yes";;
+         [case $host_os in
+            aix*) gl_cv_func_strndup_works="guessing no";;
+            *)    gl_cv_func_strndup_works="guessing yes";;
           esac
-changequote([,])dnl
          ])])
     case $gl_cv_func_strndup_works in
       *no) REPLACE_STRNDUP=1 ;;
-- 
2.34.1

>From f9da9cbb88036d5dae18df9394c1e2fe6a6bc3a8 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:10:23 +0100
Subject: [PATCH 08/23] strndup tests: Verify N3322 functionality.

* tests/test-strndup.c: New file.
* modules/strndup-tests: New file.
---
 ChangeLog             |  4 ++++
 modules/strndup-tests | 11 +++++++++++
 tests/test-strndup.c  | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 modules/strndup-tests
 create mode 100644 tests/test-strndup.c

diff --git a/ChangeLog b/ChangeLog
index 06ccb74f9a..b61465d749 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
+	strndup tests: Verify N3322 functionality.
+	* tests/test-strndup.c: New file.
+	* modules/strndup-tests: New file.
+
 	strndup: Guarantee N3322 functionality.
 	* m4/strndup.m4 (gl_FUNC_STRNDUP): Check against the AIX bug.
 	* doc/posix-functions/strndup.texi: Mention the AIX bug.
diff --git a/modules/strndup-tests b/modules/strndup-tests
new file mode 100644
index 0000000000..9b354d5b04
--- /dev/null
+++ b/modules/strndup-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-strndup.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strndup
+check_PROGRAMS += test-strndup
diff --git a/tests/test-strndup.c b/tests/test-strndup.c
new file mode 100644
index 0000000000..a9a1625826
--- /dev/null
+++ b/tests/test-strndup.c
@@ -0,0 +1,38 @@
+/* Test of strndup() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (strndup (NULL, 0) != NULL);
+  ASSERT (value);
+
+  return test_exit_status;
+}
-- 
2.34.1

From a9309034d275a97956c0c8854e943e25cda57039 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:02 +0100
Subject: [PATCH 09/23] strncat tests: Verify N3322 functionality.

* tests/test-strncat.c (main): Add a zero-size test.
---
 ChangeLog            |  5 +++++
 tests/test-strncat.c | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index b61465d749..15d587da21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	strncat tests: Verify N3322 functionality.
+	* tests/test-strncat.c (main): Add a zero-size test.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	strndup tests: Verify N3322 functionality.
diff --git a/tests/test-strncat.c b/tests/test-strncat.c
index 0ee5089e58..c4668d95b4 100644
--- a/tests/test-strncat.c
+++ b/tests/test-strncat.c
@@ -58,5 +58,21 @@ main ()
     check (input, SIZEOF (input));
   }
 
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+#if 0 /* I think this is invalid, per ISO C 23 § 7.26.3.2.  */
+  value = (strncat (NULL, "x", 0) == NULL);
+  ASSERT (value);
+#endif
+
+  {
+    char y[1];
+    value = (strncat (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
   return test_exit_status;
 }
-- 
2.34.1

>From 62aeb940b3d6b43ee9f59cd64572832af4aeec83 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:10 +0100
Subject: [PATCH 10/23] memcmp tests: Verify N3322 functionality.

* tests/test-memcmp.c (main): Add zero-size tests.
---
 ChangeLog           |  5 +++++
 tests/test-memcmp.c | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 15d587da21..79c9c8ed36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	memcmp tests: Verify N3322 functionality.
+	* tests/test-memcmp.c (main): Add zero-size tests.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	strncat tests: Verify N3322 functionality.
diff --git a/tests/test-memcmp.c b/tests/test-memcmp.c
index 11ae43719c..633ba9d193 100644
--- a/tests/test-memcmp.c
+++ b/tests/test-memcmp.c
@@ -75,5 +75,19 @@ main (void)
       }
   }
 
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (memcmp (NULL, "x", 0) == 0);
+  ASSERT (value);
+
+  value = (memcmp ("x", NULL, 0) == 0);
+  ASSERT (value);
+
+  value = (memcmp (NULL, NULL, 0) == 0);
+  ASSERT (value);
+
   return test_exit_status;
 }
-- 
2.34.1

>From 5e713ecd96671087298e8d0e2e9badcd7d592ced Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:12 +0100
Subject: [PATCH 11/23] strncmp tests: Verify N3322 functionality.

* modules/strncmp: New file.
* doc/posix-functions/strncmp.texi: Mention the new module.
* tests/test-strncmp.c: New file.
* modules/strncmp-tests: New file.
---
 ChangeLog                        |  8 ++++++
 doc/posix-functions/strncmp.texi |  3 ++-
 modules/strncmp                  | 25 ++++++++++++++++++
 modules/strncmp-tests            | 11 ++++++++
 tests/test-strncmp.c             | 44 ++++++++++++++++++++++++++++++++
 5 files changed, 90 insertions(+), 1 deletion(-)
 create mode 100644 modules/strncmp
 create mode 100644 modules/strncmp-tests
 create mode 100644 tests/test-strncmp.c

diff --git a/ChangeLog b/ChangeLog
index 79c9c8ed36..699893401b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	strncmp tests: Verify N3322 functionality.
+	* modules/strncmp: New file.
+	* doc/posix-functions/strncmp.texi: Mention the new module.
+	* tests/test-strncmp.c: New file.
+	* modules/strncmp-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	memcmp tests: Verify N3322 functionality.
diff --git a/doc/posix-functions/strncmp.texi b/doc/posix-functions/strncmp.texi
index df0f0afbeb..2cccd766ea 100644
--- a/doc/posix-functions/strncmp.texi
+++ b/doc/posix-functions/strncmp.texi
@@ -4,7 +4,8 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/strncmp.html}
 
-Gnulib module: ---
+Gnulib module: strncmp
+@mindex strncmp
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/modules/strncmp b/modules/strncmp
new file mode 100644
index 0000000000..443c367ef2
--- /dev/null
+++ b/modules/strncmp
@@ -0,0 +1,25 @@
+Description:
+Compare the initial part of two strings.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/strncmp-tests b/modules/strncmp-tests
new file mode 100644
index 0000000000..a3a34c01e1
--- /dev/null
+++ b/modules/strncmp-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-strncmp.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strncmp
+check_PROGRAMS += test-strncmp
diff --git a/tests/test-strncmp.c b/tests/test-strncmp.c
new file mode 100644
index 0000000000..51c2be49ed
--- /dev/null
+++ b/tests/test-strncmp.c
@@ -0,0 +1,44 @@
+/* Test of strncmp() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (strncmp (NULL, "x", 0) == 0);
+  ASSERT (value);
+
+  value = (strncmp ("x", NULL, 0) == 0);
+  ASSERT (value);
+
+  value = (strncmp (NULL, NULL, 0) == 0);
+  ASSERT (value);
+
+  return test_exit_status;
+}
-- 
2.34.1

>From 140aff1babcfa58d49c9f60ed61b9c7720e6b1c5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:14 +0100
Subject: [PATCH 12/23] memchr tests: Verify N3322 functionality.

* tests/test-memchr.c (main): Add a zero-size test.
---
 ChangeLog           | 5 +++++
 tests/test-memchr.c | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 699893401b..5748bc9fe6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	memchr tests: Verify N3322 functionality.
+	* tests/test-memchr.c (main): Add a zero-size test.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	strncmp tests: Verify N3322 functionality.
diff --git a/tests/test-memchr.c b/tests/test-memchr.c
index 9111371a15..ffa3a0ac2c 100644
--- a/tests/test-memchr.c
+++ b/tests/test-memchr.c
@@ -133,5 +133,12 @@ main (void)
 
   free (input);
 
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+  {
+    int volatile value = (memchr (NULL, '?', 0) == NULL);
+    ASSERT (value);
+  }
+
   return test_exit_status;
 }
-- 
2.34.1

>From ce762a900482ab21dca4fd6be6fee3a7fa7caf4c Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:17 +0100
Subject: [PATCH 13/23] memset tests: Verify N3322 functionality.

* tests/test-memset.c: New file.
* modules/memset-tests: New file.
---
 ChangeLog            |  6 ++++++
 modules/memset-tests | 11 +++++++++++
 tests/test-memset.c  | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
 create mode 100644 modules/memset-tests
 create mode 100644 tests/test-memset.c

diff --git a/ChangeLog b/ChangeLog
index 5748bc9fe6..d36d51ebb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	memset tests: Verify N3322 functionality.
+	* tests/test-memset.c: New file.
+	* modules/memset-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	memchr tests: Verify N3322 functionality.
diff --git a/modules/memset-tests b/modules/memset-tests
new file mode 100644
index 0000000000..5465ec52ee
--- /dev/null
+++ b/modules/memset-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-memset.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-memset
+check_PROGRAMS += test-memset
diff --git a/tests/test-memset.c b/tests/test-memset.c
new file mode 100644
index 0000000000..04fbc28fce
--- /dev/null
+++ b/tests/test-memset.c
@@ -0,0 +1,37 @@
+/* Test of memset() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <string.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+  {
+    int volatile value = (memset (NULL, '?', 0) == NULL);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From a8fccc67ddbb1dbce3473ce99fc1c4ba72565158 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:20 +0100
Subject: [PATCH 14/23] memset_explicit tests: Verify N3322 functionality.

* tests/test-memset_explicit.c (main): Add a zero-size test.
---
 ChangeLog                    | 5 +++++
 tests/test-memset_explicit.c | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index d36d51ebb8..1c6facac48 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	memset_explicit tests: Verify N3322 functionality.
+	* tests/test-memset_explicit.c (main): Add a zero-size test.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	memset tests: Verify N3322 functionality.
diff --git a/tests/test-memset_explicit.c b/tests/test-memset_explicit.c
index 477415b45f..79f2aad570 100644
--- a/tests/test-memset_explicit.c
+++ b/tests/test-memset_explicit.c
@@ -243,5 +243,12 @@ main ()
   test_heap ();
   test_stack ();
 
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+  {
+    int volatile value = (memset_explicit (NULL, '?', 0) == NULL);
+    ASSERT (value);
+  }
+
   return test_exit_status;
 }
-- 
2.34.1

>From 4e556e28f9c973de734ae1ef2eb89a4b581fbab6 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:22 +0100
Subject: [PATCH 15/23] wcsncpy tests: Verify N3322 functionality.

* tests/test-wcsncpy.c: New file.
* modules/wcsncpy-tests: New file.
---
 ChangeLog             |  6 ++++++
 modules/wcsncpy-tests | 11 +++++++++++
 tests/test-wcsncpy.c  | 44 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 modules/wcsncpy-tests
 create mode 100644 tests/test-wcsncpy.c

diff --git a/ChangeLog b/ChangeLog
index 1c6facac48..db888d854a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	wcsncpy tests: Verify N3322 functionality.
+	* tests/test-wcsncpy.c: New file.
+	* modules/wcsncpy-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	memset_explicit tests: Verify N3322 functionality.
diff --git a/modules/wcsncpy-tests b/modules/wcsncpy-tests
new file mode 100644
index 0000000000..89706be6df
--- /dev/null
+++ b/modules/wcsncpy-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-wcsncpy.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-wcsncpy
+check_PROGRAMS += test-wcsncpy
diff --git a/tests/test-wcsncpy.c b/tests/test-wcsncpy.c
new file mode 100644
index 0000000000..d741a3d1ab
--- /dev/null
+++ b/tests/test-wcsncpy.c
@@ -0,0 +1,44 @@
+/* Test of wcsncpy() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (wcsncpy (NULL, L"x", 0) == NULL);
+  ASSERT (value);
+
+  {
+    wchar_t y[1];
+    value = (wcsncpy (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From 184e2c51ba01f19bfcf729860a1b97b255e93e23 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:25 +0100
Subject: [PATCH 16/23] wmemcpy tests: Verify N3322 functionality.

* tests/test-wmemcpy.c: New file.
* modules/wmemcpy-tests: New file.
---
 ChangeLog             |  6 ++++++
 modules/wmemcpy-tests | 11 +++++++++++
 tests/test-wmemcpy.c  | 44 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 modules/wmemcpy-tests
 create mode 100644 tests/test-wmemcpy.c

diff --git a/ChangeLog b/ChangeLog
index db888d854a..10ba705752 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	wmemcpy tests: Verify N3322 functionality.
+	* tests/test-wmemcpy.c: New file.
+	* modules/wmemcpy-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	wcsncpy tests: Verify N3322 functionality.
diff --git a/modules/wmemcpy-tests b/modules/wmemcpy-tests
new file mode 100644
index 0000000000..18ed514d64
--- /dev/null
+++ b/modules/wmemcpy-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-wmemcpy.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-wmemcpy
+check_PROGRAMS += test-wmemcpy
diff --git a/tests/test-wmemcpy.c b/tests/test-wmemcpy.c
new file mode 100644
index 0000000000..1f67d4d5c7
--- /dev/null
+++ b/tests/test-wmemcpy.c
@@ -0,0 +1,44 @@
+/* Test of wmemcpy() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (wmemcpy (NULL, L"x", 0) == NULL);
+  ASSERT (value);
+
+  {
+    wchar_t y[1];
+    value = (wmemcpy (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From c28fc40024adf6ce366d09eff684628d29f4dc40 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:29 +0100
Subject: [PATCH 17/23] wmemmove tests: Verify N3322 functionality.

* tests/test-wmemmove.c: New file.
* modules/wmemmove-tests: New file.
---
 ChangeLog              |  6 ++++++
 modules/wmemmove-tests | 11 +++++++++++
 tests/test-wmemmove.c  | 44 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 modules/wmemmove-tests
 create mode 100644 tests/test-wmemmove.c

diff --git a/ChangeLog b/ChangeLog
index 10ba705752..5f1a392fb4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	wmemmove tests: Verify N3322 functionality.
+	* tests/test-wmemmove.c: New file.
+	* modules/wmemmove-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	wmemcpy tests: Verify N3322 functionality.
diff --git a/modules/wmemmove-tests b/modules/wmemmove-tests
new file mode 100644
index 0000000000..d2ba04c608
--- /dev/null
+++ b/modules/wmemmove-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-wmemmove.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-wmemmove
+check_PROGRAMS += test-wmemmove
diff --git a/tests/test-wmemmove.c b/tests/test-wmemmove.c
new file mode 100644
index 0000000000..24a73a120c
--- /dev/null
+++ b/tests/test-wmemmove.c
@@ -0,0 +1,44 @@
+/* Test of wmemmove() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (wmemmove (NULL, L"x", 0) == NULL);
+  ASSERT (value);
+
+  {
+    wchar_t y[1];
+    value = (wmemmove (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From 101b9d7f82f73fac4da98d26af461e975eeafd00 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
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  <br...@clisp.org>
+
+	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  <br...@clisp.org>
 
 	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 <wchar.h>
+              #include <stddef.h>
+            ]], [[
+              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

From a366348be2d8859a86d40eff43a588a4ee0cbd88 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:11:39 +0100
Subject: [PATCH 19/23] wcsncat tests: Verify N3322 functionality.

* tests/test-wcsncat.c: New file.
* modules/wcsncat-tests: New file.
---
 ChangeLog             |  4 ++++
 modules/wcsncat-tests | 11 ++++++++++
 tests/test-wcsncat.c  | 48 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 modules/wcsncat-tests
 create mode 100644 tests/test-wcsncat.c

diff --git a/ChangeLog b/ChangeLog
index c019e77f02..0bb5d71f79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
+	wcsncat tests: Verify N3322 functionality.
+	* tests/test-wcsncat.c: New file.
+	* modules/wcsncat-tests: New file.
+
 	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
diff --git a/modules/wcsncat-tests b/modules/wcsncat-tests
new file mode 100644
index 0000000000..d498dade80
--- /dev/null
+++ b/modules/wcsncat-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-wcsncat.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-wcsncat
+check_PROGRAMS += test-wcsncat
diff --git a/tests/test-wcsncat.c b/tests/test-wcsncat.c
new file mode 100644
index 0000000000..b8479dfb5e
--- /dev/null
+++ b/tests/test-wcsncat.c
@@ -0,0 +1,48 @@
+/* Test of wcsncat() function.
+   Copyright (C) 2010-2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <br...@clisp.org>, 2024.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main ()
+{
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+#if 0 /* I think this is invalid, per ISO C 23 § 7.31.4.3.2.  */
+  value = (wcsncat (NULL, L"x", 0) == NULL);
+  ASSERT (value);
+#endif
+
+  {
+    wchar_t y[1];
+    value = (wcsncat (y, NULL, 0) == y);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From 3ee8ce232478edbe1b93456285b29340fe2eee3e Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:12:06 +0100
Subject: [PATCH 20/23] wcsncmp tests: Verify N3322 functionality.

* tests/test-wcsncmp.c (main): Add zero-size tests.
---
 ChangeLog            |  5 +++++
 tests/test-wcsncmp.c | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 0bb5d71f79..0efaf7854b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	wcsncmp tests: Verify N3322 functionality.
+	* tests/test-wcsncmp.c (main): Add zero-size tests.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	wcsncat tests: Verify N3322 functionality.
diff --git a/tests/test-wcsncmp.c b/tests/test-wcsncmp.c
index 6db6c248ef..c1fe103ef4 100644
--- a/tests/test-wcsncmp.c
+++ b/tests/test-wcsncmp.c
@@ -178,5 +178,19 @@ main (int argc, char *argv[])
       }
   }
 
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (wcsncmp (NULL, L"x", 0) == 0);
+  ASSERT (value);
+
+  value = (wcsncmp (L"x", NULL, 0) == 0);
+  ASSERT (value);
+
+  value = (wcsncmp (NULL, NULL, 0) == 0);
+  ASSERT (value);
+
   return test_exit_status;
 }
-- 
2.34.1

>From 9a8851975400ae3d5c2fed6c80c8346565ed390b Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:12:08 +0100
Subject: [PATCH 21/23] wmemcmp tests: Verify N3322 functionality.

* tests/test-wmemcmp.c (main): Add zero-size tests.
---
 ChangeLog            |  5 +++++
 tests/test-wmemcmp.c | 14 ++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 0efaf7854b..6945b84e9e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	wmemcmp tests: Verify N3322 functionality.
+	* tests/test-wmemcmp.c (main): Add zero-size tests.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	wcsncmp tests: Verify N3322 functionality.
diff --git a/tests/test-wmemcmp.c b/tests/test-wmemcmp.c
index 692fcb5e07..d7992b59ce 100644
--- a/tests/test-wmemcmp.c
+++ b/tests/test-wmemcmp.c
@@ -91,5 +91,19 @@ main (int argc, char *argv[])
     ASSERT (wmemcmp (input2, input1, 1) > 0);
   }
 
+  int volatile value;
+
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+
+  value = (wmemcmp (NULL, L"x", 0) == 0);
+  ASSERT (value);
+
+  value = (wmemcmp (L"x", NULL, 0) == 0);
+  ASSERT (value);
+
+  value = (wmemcmp (NULL, NULL, 0) == 0);
+  ASSERT (value);
+
   return test_exit_status;
 }
-- 
2.34.1

>From f00b47ec1a696fb0757436e9228d2b44881cd70f Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:12:11 +0100
Subject: [PATCH 22/23] wmemchr tests: Verify N3322 functionality.

* tests/test-wmemchr.c: New file.
* modules/wmemchr-tests: New file.
---
 ChangeLog             |  6 ++++++
 modules/wmemchr-tests | 11 +++++++++++
 tests/test-wmemchr.c  | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
 create mode 100644 modules/wmemchr-tests
 create mode 100644 tests/test-wmemchr.c

diff --git a/ChangeLog b/ChangeLog
index 6945b84e9e..3ab7003b76 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	wmemchr tests: Verify N3322 functionality.
+	* tests/test-wmemchr.c: New file.
+	* modules/wmemchr-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	wmemcmp tests: Verify N3322 functionality.
diff --git a/modules/wmemchr-tests b/modules/wmemchr-tests
new file mode 100644
index 0000000000..f1de54d296
--- /dev/null
+++ b/modules/wmemchr-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-wmemchr.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-wmemchr
+check_PROGRAMS += test-wmemchr
diff --git a/tests/test-wmemchr.c b/tests/test-wmemchr.c
new file mode 100644
index 0000000000..3068eb983d
--- /dev/null
+++ b/tests/test-wmemchr.c
@@ -0,0 +1,37 @@
+/* Test of wmemchr() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+  {
+    int volatile value = (wmemchr (NULL, L'?', 0) == NULL);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

>From 4bb67e4ede09108661770ea6a88f4733ca658170 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Tue, 5 Nov 2024 21:12:14 +0100
Subject: [PATCH 23/23] wmemset tests: Verify N3322 functionality.

* tests/test-wmemset.c: New file.
* modules/wmemset-tests: New file.
---
 ChangeLog             |  6 ++++++
 modules/wmemset-tests | 11 +++++++++++
 tests/test-wmemset.c  | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
 create mode 100644 modules/wmemset-tests
 create mode 100644 tests/test-wmemset.c

diff --git a/ChangeLog b/ChangeLog
index 3ab7003b76..a7af54907a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-11-05  Bruno Haible  <br...@clisp.org>
+
+	wmemset tests: Verify N3322 functionality.
+	* tests/test-wmemset.c: New file.
+	* modules/wmemset-tests: New file.
+
 2024-11-05  Bruno Haible  <br...@clisp.org>
 
 	wmemchr tests: Verify N3322 functionality.
diff --git a/modules/wmemset-tests b/modules/wmemset-tests
new file mode 100644
index 0000000000..b6c4adf721
--- /dev/null
+++ b/modules/wmemset-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-wmemset.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-wmemset
+check_PROGRAMS += test-wmemset
diff --git a/tests/test-wmemset.c b/tests/test-wmemset.c
new file mode 100644
index 0000000000..6d7f427189
--- /dev/null
+++ b/tests/test-wmemset.c
@@ -0,0 +1,37 @@
+/* Test of wmemset() function.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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 <config.h>
+
+/* Specification.  */
+#include <wchar.h>
+
+#include <stddef.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* Test zero-length operations on NULL pointers, allowed by
+     <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
+  {
+    int volatile value = (wmemset (NULL, L'?', 0) == NULL);
+    ASSERT (value);
+  }
+
+  return test_exit_status;
+}
-- 
2.34.1

Reply via email to