Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed,  2 Oct 2024 13:39:14 +0530 Brahmajit Das <brahmajit.xyz@xxxxxxxxx> wrote:

> GCC 15 enables -Werror=unterminated-string-initialization by default.
> This results in the following build error/s
> fs/proc/task_mmu.c:917:49: error: initializer-string for array of ‘char’ is too long [-Werror=unterminate d-string-initialization]
>   917 |                 [0 ... (BITS_PER_LONG-1)] = "??",
>       |                                                 ^~~~
> fs/proc/task_mmu.c:917:49: error: initializer-string for array of ‘char’ is too long [-Werror=unterminate d-string-initialization]
> fs/proc/task_mmu.c:917:49: error: initializer-string for array of ‘char’ is too long [-Werror=unterminate d-string-initialization]
> fs/proc/task_mmu.c:917:49: error: initializer-string for array of ‘char’ is too long [-Werror=unterminate d-string-initialization]
> fs/proc/task_mmu.c:917:49: error: initializer-string for array of ‘char’ is too long [-Werror=unterminate d-string-initialization]
> fs/proc/task_mmu.c:917:49: error: initializer-string for array of ‘char’ is too long [-Werror=unterminate d-string-initialization]
> ...
> 
> To fix this, the length of the second argument of arary mnemonics needs

"array"

> to be 3 instead of previously set 2 (i.e. from [BITS_PER_LONG][2] to
> [BITS_PER_LONG][3])
> 

Yes, I'm not surprised that little party trick we used in there fools
gcc.  And really it deserves to die.

> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -909,8 +909,15 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>  {
>  	/*
>  	 * Don't forget to update Documentation/ on changes.
> +	 *
> +	 * The length of the second argument of arary mnemonics

"array".  But really, just using "mnemonics[]" conveys all we need.

> +	 * needs to be 3 instead of previously set 2
> +	 * (i.e. from [BITS_PER_LONG][2] to [BITS_PER_LONG][3])
> +	 * to avoid spurious
> +	 * -Werror=unterminated-string-initialization warning
> +	 *  with GCC 15
>  	 */
> -	static const char mnemonics[BITS_PER_LONG][2] = {
> +	static const char mnemonics[BITS_PER_LONG][3] = {
>  		/*
>  		 * In case if we meet a flag we don't know about.
>  		 */

If we want to preserve the party trick then perhaps we can use

-                [0 ... (BITS_PER_LONG-1)] = { "??" },
+                [0 ... (BITS_PER_LONG-1)] = { '?', '?' },

and this will shut gcc up?

If we do remove the party trick (as you have done) then this:

		if (vma->vm_flags & (1UL << i)) {
			seq_putc(m, mnemonics[i][0]);
			seq_putc(m, mnemonics[i][1]);
			seq_putc(m, ' ');
		}

can be simplified (and probably sped up) with

		
		if (vma->vm_flags & (1UL << i))
			seq_printf(m, "%s ", mnemonics[i]);

yes?





[Index of Archives]     [Linux Kernel]     [Linux USB Development]     [Yosemite News]     [Linux SCSI]

  Powered by Linux