All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Brahmajit Das <brahmajit.xyz@gmail.com>
Cc: david@redhat.com, gorcunov@openvz.org,
	linux-next@vger.kernel.org, sfr@canb.auug.org.au
Subject: Re: [PATCH v3 1/1] fs/proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
Date: Mon, 7 Oct 2024 19:08:13 -0700	[thread overview]
Message-ID: <20241007190813.f4effd5788cf7362a4fda19f@linux-foundation.org> (raw)
In-Reply-To: <20241005063700.2241027-1-brahmajit.xyz@gmail.com>

On Sat,  5 Oct 2024 12:07:00 +0530 Brahmajit Das <brahmajit.xyz@gmail.com> wrote:

> show show_smap_vma_flags() has been using misspelled initializer in
> mnemonics[] - it needed to initialize 2 element array of char and it
> used NUL-padded 2 character string literals (i.e. 3-element
> initializer).
> 
> This has been spotted by gcc-15[*]; prior to that gcc quietly dropped
> the 3rd eleemnt of initializers. To fix this we are increasing the size
> of mnemonics[] (from mnemonics[BITS_PER_LONG][2] to
> mnemonics[BITS_PER_LONG][3]) to accomodate the NUL-padded string
> literals.
> 
> This also helps us in simplyfying the logic for printing of the flags as
> instead of printing each character from the mnemonics[], we can just
> print the mnemonics[] using seq_printf.
> 
> [*]: 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]

> Cc: david@redhat.com, gorcunov@openvz.org, linux-next@vger.kernel.org, sfr@canb.auug.org.au

It is strange to cc only linux-next.  It isn't really a development
mailing list.  Please include an appropriate development list and/or
linux-kernel on patches.

> --- 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 mnemonics[]
> +	 * 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.
>  		 */
> @@ -987,11 +994,8 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>  	for (i = 0; i < BITS_PER_LONG; i++) {
>  		if (!mnemonics[i][0])
>  			continue;
> -		if (vma->vm_flags & (1UL << i)) {
> -			seq_putc(m, mnemonics[i][0]);
> -			seq_putc(m, mnemonics[i][1]);
> -			seq_putc(m, ' ');
> -		}
> +		if (vma->vm_flags & (1UL << i))
> +			seq_printf(m, "%s ", mnemonics[i]);
>  	}
>  	seq_putc(m, '\n');
>  }

Patch looks good.  I'll add this to the changelog:


Stephen pointed out:

: The C standard explicitly allows for a string initializer to be too long
: due to the NUL byte at the end ...  so this warning may be overzealous.

but let's make the warning go away anwyay.



  reply	other threads:[~2024-10-08  2:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02  8:05 [PATCH 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization Brahmajit Das
2024-10-02  8:09 ` [PATCH v2 " Brahmajit Das
2024-10-02 21:48   ` Andrew Morton
2024-10-02 23:30     ` Stephen Rothwell
2024-10-02 23:39     ` Stephen Rothwell
2024-10-04 20:16     ` Brahmajit
2024-10-04 21:12     ` Brahmajit
2024-10-04 21:58       ` Andrew Morton
2024-10-05  6:37         ` [PATCH v3 1/1] fs/proc: " Brahmajit Das
2024-10-08  2:08           ` Andrew Morton [this message]
2024-10-28  8:02             ` Cyrill Gorcunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241007190813.f4effd5788cf7362a4fda19f@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=brahmajit.xyz@gmail.com \
    --cc=david@redhat.com \
    --cc=gorcunov@openvz.org \
    --cc=linux-next@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.