[PATCH 5/9] string-h: Use _GL_ATTRIBUTE_NONNULL_IF_NONZERO in explicit_bzero

Lasse Collin <[email protected]> Fri, 31 Jul 2026 18:33:39 +0300
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <[email protected]>
In OpenBSD and FreeBSD, bzero is documented to do nothing if the
length is zero, and explicit_bzero is documented to behave the same
as bzero. Thus, explicit_bzero(NULL, 0) is fine.
* lib/string.in.h: Use _GL_ATTRIBUTE_NONNULL_IF_NONZERO instead of
_GL_ARG_NONNULL in explicit_bzero.
---
 ChangeLog       | 9 +++++++++
 lib/string.in.h | 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 436beb8e26..8f057a5fb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-07-31  Lasse Collin  <[email protected]>
+
+	string-h: Use _GL_ATTRIBUTE_NONNULL_IF_NONZERO in explicit_bzero.
+	In OpenBSD and FreeBSD, bzero is documented to do nothing if the
+	length is zero, and explicit_bzero is documented to behave the same
+	as bzero. Thus, explicit_bzero(NULL, 0) is fine.
+	* lib/string.in.h: Use _GL_ATTRIBUTE_NONNULL_IF_NONZERO instead of
+	_GL_ARG_NONNULL in explicit_bzero.
+
 2026-07-31  Lasse Collin  <[email protected]>
 
 	string-h: Use _GL_ATTRIBUTE_NONNULL_IF_NONZERO in mempcpy.
diff --git a/lib/string.in.h b/lib/string.in.h
index f21ebce70f..0d01995d0e 100644
--- a/lib/string.in.h
+++ b/lib/string.in.h
@@ -312,7 +312,8 @@ _GL_EXTERN_C void *memset_explicit (void *__s, int __c, size_t __n)
 #if @GNULIB_EXPLICIT_BZERO@
 # if ! @HAVE_EXPLICIT_BZERO@
 _GL_FUNCDECL_SYS (explicit_bzero, void,
-                  (void *__dest, size_t __n), _GL_ARG_NONNULL ((1)));
+                  (void *__dest, size_t __n),
+                  _GL_ATTRIBUTE_NONNULL_IF_NONZERO (1, 2));
 # endif
 _GL_CXXALIAS_SYS (explicit_bzero, void, (void *__dest, size_t __n));
 _GL_CXXALIASWARN (explicit_bzero);
-- 
2.55.0