Collin Funk <[email protected]> writes:

> I pushed the attached patch to silence this warning:
>
>     $ gnulib-tool --create-testdir --dir testdir1 regex
>     $ cd testdir1
>     $ ./configure CFLAGS='-Wzero-as-null-pointer-constant'
>     $ make
>     [...]
>     gcc -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1   
> -Wzero-as-null-pointer-constant -MT regex.o -MD -MP -MF $depbase.Tpo -c -o 
> regex.o regex.c &&\
>     mv -f $depbase.Tpo $depbase.Po
>     In file included from regex.c:72:
>     regexec.c: In function ‘merge_state_with_log’:
>     regexec.c:2344:40: warning: zero as null pointer constant 
> [-Wzero-as-null-pointer-constant]
>      2344 |   else if (mctx->state_log[cur_idx] == 0)
>           |
>     [...]
>
> The 'git blame' shows the code is many years old. I just only noticed it
> now since we began replacing glibc's regex.

Here is another one:

    $ gnulib-tool --create-testdir --dir testdir1 readutmp
    $ cd testdir1
    $ ./configure --enable-systemd CFLAGS='-Wzero-as-null-pointer-constant'
    $ make
    [...]
    gcc -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1   
-Wzero-as-null-pointer-constant -MT readutmp.o -MD -MP -MF .deps/readutmp.Tpo 
-c -o readutmp.o readutmp.c
    readutmp.c: In function ‘read_utmp_from_systemd’:
    readutmp.c:801:26: warning: zero as null pointer constant 
[-Wzero-as-null-pointer-constant]
      801 |   struct utmp_alloc a = {0};
          |                          ^
    [...]

I was tempted to not fix it since {0} is a convenient way to zero all
the struct members. However, I see Bruno changed another instance of
this initialization in lib/readutmp.c in commit
f3d96537413f1fc0913cd290b1eea35386295b1b. However, this one was hidden
behind --enable-systemd.

Pushed the attached patch to silence it.

Collin

>From d8d9e3289f51b074b9df0fed52e3b3868683f83e Mon Sep 17 00:00:00 2001
Message-ID: <d8d9e3289f51b074b9df0fed52e3b3868683f83e.1776566950.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Sat, 18 Apr 2026 19:42:21 -0700
Subject: [PATCH] readutmp: Silence -Wzero-as-null-pointer-constant warning.

* lib/readutmp.c (read_utmp_from_systemd): Initialize all of the struct
members and use NULL for the pointer.
---
 ChangeLog      | 6 ++++++
 lib/readutmp.c | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 39529954bc..14a27b0c21 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2026-04-18  Collin Funk  <[email protected]>
+
+	readutmp: Silence -Wzero-as-null-pointer-constant warning.
+	* lib/readutmp.c (read_utmp_from_systemd): Initialize all of the struct
+	members and use NULL for the pointer.
+
 2026-04-16  Collin Funk  <[email protected]>
 
 	regex: Silence -Wzero-as-null-pointer-constant warning.
diff --git a/lib/readutmp.c b/lib/readutmp.c
index 5d84722404..14293f4006 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -798,7 +798,7 @@ static int
 read_utmp_from_systemd (idx_t *n_entries, STRUCT_UTMP **utmp_buf, int options)
 {
   /* Fill entries, simulating what a utmp file would contain.  */
-  struct utmp_alloc a = {0};
+  struct utmp_alloc a = { NULL, 0, 0, 0 };
 
   /* Synthesize a BOOT_TIME entry.  */
   if (!(options & (READ_UTMP_USER_PROCESS | READ_UTMP_NO_BOOT_TIME)))
-- 
2.53.0

Reply via email to