From 155847c72dd91117887b85f54ef006f7690c38de Mon Sep 17 00:00:00 2001 From: Tony Hutter Date: Wed, 16 Apr 2025 09:33:29 -0700 Subject: [PATCH] GCC 15: Fix unterminated-string-initialization (#17244) Fix build errors on Fedora 42 like: module/zcommon/zfs_valstr.c:193:16: error: initializer-string for array of 'char' truncates NUL terminator but destination lacks 'nonstring' attribute (3 chars into 2 available) The arrays in zpool_vdev_os.c and zfs_valstr.c don't need to be NULL terminated, but we do so to make GCC happy. Closes: #17242 Signed-off-by: Tony Hutter Reviewed-by: Alexander Motin Reviewed-by: Brian Behlendorf --- cmd/zpool/os/linux/zpool_vdev_os.c | 3 ++- module/zcommon/zfs_valstr.c | 4 +++- tests/zfs-tests/cmd/file/largest_file.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/zpool/os/linux/zpool_vdev_os.c b/cmd/zpool/os/linux/zpool_vdev_os.c index 8da9aece4..344693a47 100644 --- a/cmd/zpool/os/linux/zpool_vdev_os.c +++ b/cmd/zpool/os/linux/zpool_vdev_os.c @@ -88,7 +88,8 @@ typedef struct vdev_disk_db_entry { - char id[24]; + /* 24 byte name + 1 byte NULL terminator to make GCC happy */ + char id[25]; int sector_size; } vdev_disk_db_entry_t; diff --git a/module/zcommon/zfs_valstr.c b/module/zcommon/zfs_valstr.c index 546de63c8..ab2599e0c 100644 --- a/module/zcommon/zfs_valstr.c +++ b/module/zcommon/zfs_valstr.c @@ -39,7 +39,9 @@ */ typedef struct { const char vb_bit; - const char vb_pair[2]; + + /* 2 byte name + 1 byte NULL terminator to make GCC happy */ + const char vb_pair[3]; const char *vb_name; } valstr_bit_t; diff --git a/tests/zfs-tests/cmd/file/largest_file.c b/tests/zfs-tests/cmd/file/largest_file.c index 82b795601..a876d8327 100644 --- a/tests/zfs-tests/cmd/file/largest_file.c +++ b/tests/zfs-tests/cmd/file/largest_file.c @@ -62,7 +62,7 @@ main(int argc, char **argv) offset_t llseek_ret = 0; int write_ret = 0; int err = 0; - char mybuf[5] = "aaaa\0"; + char mybuf[5] = "aaaa"; char *testfile; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; struct sigaction sa;