]> Savannah Git Hosting - gnulib.git/commitdiff
strncat tests: Verify N3322 functionality.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 20:11:02 +0000 (21:11 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 5 Nov 2024 21:38:31 +0000 (22:38 +0100)
* tests/test-strncat.c (main): Add a zero-size test.

ChangeLog
tests/test-strncat.c

index b61465d749ddbe8a20061db839c2853506517f53..15d587da219f05bc7109edea79325ed9623c950d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-11-05  Bruno Haible  <bruno@clisp.org>
+
+       strncat tests: Verify N3322 functionality.
+       * tests/test-strncat.c (main): Add a zero-size test.
+
 2024-11-05  Bruno Haible  <bruno@clisp.org>
 
        strndup tests: Verify N3322 functionality.
index 0ee5089e582e3d9a69529720f8f7744e101b6a2c..c4668d95b4b474b5bf89309292c7743d6962fb7e 100644 (file)
@@ -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;
 }