Re: Build failure with GCC 15 due to -Werror=unterminated-string-initialization

From: Al Viro
Date: Wed Oct 02 2024 - 17:47:14 EST


On Thu, Oct 03, 2024 at 02:46:48AM +0530, Brahmajit wrote:
> I'm building the latest kernel with GCC 15 and got this build failure
>
> fs/qnx6/inode.c: In function ‘qnx6_checkroot’:
> fs/qnx6/inode.c:182:41: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> 182 | static char match_root[2][3] = {".\0\0", "..\0"};
> | ^~~~~~~
> fs/qnx6/inode.c:182:50: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> 182 | static char match_root[2][3] = {".\0\0", "..\0"};
> | ^~~~~~
>
> This is due to GCC 15 now enables
> -Werror=unterminated-string-initialization by default.
> This is not the only error, there are many such build failures in
> various subsystems, some of theme are easy to fix, while some are not.
> In this case I was thinking of something like:
>
> --- a/fs/qnx6/inode.c
> +++ b/fs/qnx6/inode.c
> @@ -179,7 +179,7 @@ static int qnx6_statfs(struct dentry *dentry, struct kstatfs *buf)
> */
> static const char *qnx6_checkroot(struct super_block *s)
> {
> - static char match_root[2][3] = {".\0\0", "..\0"};
> + static char *match_root[][3] = {".\0\0", "..\0"};

Huh? That makes no sense whatsoever - you get a single-element
array of 3-element arrays of pointers to char.

What you have written is equivalent to
static char *s1 = ".\0\0";
static char *s2 = "..\0";
static char *match_root[1][3] = {[0][0] = s1, [0][1] = s2, [0][2] = NULL};

and match_root[0] is *NOT* a pointer to char anymore.

Just lose the last \0 in each of those string literals...