Hi Pádraig,
> lib/vasnprintf.c (divide): Avoid the undefined memcpy (..., NULL, 0).
memcpy (..., NULL, 0) is not undefined any more. It is defined since
N3322 [1] was adopted by the ISO C WG14 committee.
Work is underway in glibc, gcc, and clang, to avoid the now-unjustified UBSAN
reports [2][3][4].
Some more patches are needed to avoid such failures with ASAN or UBSAN
with coreutils [5][6]. Your patch is a third one in this category.
I don't want to have these patches applied upstream, because when
things are fixed in glibc, gcc, and clang, there will be no need for
these patches any more.
In the current state, the next step for progress are the glibc header
files. They need to be modified essentially like this:
--- /usr/include/string.h.bak 2025-09-17 16:55:42.000000000 +0200
+++ /usr/include/string.h 2025-11-05 19:20:41.445242977 +0100
@@ -41,7 +41,14 @@
/* Copy N bytes of SRC to DEST. */
extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
- size_t __n) __THROW __nonnull ((1, 2));
+ size_t __n) __THROW
+#if __GNUC__ >= 15 && !defined __clang__
+ __attribute__ ((__nonnull_if_nonzero__ (3, 1)))
+ __attribute__ ((__nonnull_if_nonzero__ (3, 2)))
+#else
+ __nonnull ((1, 2))
+#endif
+ ;
/* Copy N bytes of SRC to DEST, guaranteeing
correct behavior for overlapping strings. */
extern void *memmove (void *__dest, const void *__src, size_t __n)
Bruno
[1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=32286
[3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117023
[4] https://github.com/llvm/llvm-project/issues/95889
[5]
https://raw.githubusercontent.com/coreutils/ci-check/refs/heads/master/patches/ubsan.diff
[6]
https://raw.githubusercontent.com/coreutils/ci-check/refs/heads/master/patches/ubsan2.diff