Skip to content

Commit 155847c

Browse files
authored
GCC 15: Fix unterminated-string-initialization (openzfs#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: openzfs#17242 Signed-off-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
1 parent 4866c2f commit 155847c

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

cmd/zpool/os/linux/zpool_vdev_os.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888

8989
typedef struct vdev_disk_db_entry
9090
{
91-
char id[24];
91+
/* 24 byte name + 1 byte NULL terminator to make GCC happy */
92+
char id[25];
9293
int sector_size;
9394
} vdev_disk_db_entry_t;
9495

module/zcommon/zfs_valstr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
*/
4040
typedef struct {
4141
const char vb_bit;
42-
const char vb_pair[2];
42+
43+
/* 2 byte name + 1 byte NULL terminator to make GCC happy */
44+
const char vb_pair[3];
4345
const char *vb_name;
4446
} valstr_bit_t;
4547

tests/zfs-tests/cmd/file/largest_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ main(int argc, char **argv)
6262
offset_t llseek_ret = 0;
6363
int write_ret = 0;
6464
int err = 0;
65-
char mybuf[5] = "aaaa\0";
65+
char mybuf[5] = "aaaa";
6666
char *testfile;
6767
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
6868
struct sigaction sa;

0 commit comments

Comments
 (0)