* [PATCH 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
@ 2024-10-02 8:05 Brahmajit Das
2024-10-02 8:09 ` [PATCH v2 " Brahmajit Das
0 siblings, 1 reply; 11+ messages in thread
From: Brahmajit Das @ 2024-10-02 8:05 UTC (permalink / raw)
To: akpm, david, gorcunov; +Cc: linux-next
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) + 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
to be 3 instead of previously set 2 (i.e. from [BITS_PER_LONG][2] to
[BITS_PER_LONG][3])
Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
---
fs/proc/task_mmu.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 72f14fd59c2d..aa5780696fc1 100644
--- 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
+ * 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.
*/
--
2.46.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
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 ` Brahmajit Das
2024-10-02 21:48 ` Andrew Morton
0 siblings, 1 reply; 11+ messages in thread
From: Brahmajit Das @ 2024-10-02 8:09 UTC (permalink / raw)
To: akpm, david, gorcunov; +Cc: linux-next
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
to be 3 instead of previously set 2 (i.e. from [BITS_PER_LONG][2] to
[BITS_PER_LONG][3])
Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
---
fs/proc/task_mmu.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 72f14fd59c2d..aa5780696fc1 100644
--- 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
+ * 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.
*/
--
2.46.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
2024-10-02 8:09 ` [PATCH v2 " Brahmajit Das
@ 2024-10-02 21:48 ` Andrew Morton
2024-10-02 23:30 ` Stephen Rothwell
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: Andrew Morton @ 2024-10-02 21:48 UTC (permalink / raw)
To: Brahmajit Das; +Cc: david, gorcunov, linux-next
On Wed, 2 Oct 2024 13:39:14 +0530 Brahmajit Das <brahmajit.xyz@gmail.com> 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?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
2024-10-02 21:48 ` Andrew Morton
@ 2024-10-02 23:30 ` Stephen Rothwell
2024-10-02 23:39 ` Stephen Rothwell
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Stephen Rothwell @ 2024-10-02 23:30 UTC (permalink / raw)
To: Andrew Morton; +Cc: Brahmajit Das, david, gorcunov, linux-next
[-- Attachment #1: Type: text/plain, Size: 1895 bytes --]
Hi Andrew,
On Wed, 2 Oct 2024 14:48:06 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Wed, 2 Oct 2024 13:39:14 +0530 Brahmajit Das <brahmajit.xyz@gmail.com> 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.
However, 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
over zealous. And the code referencing these "strings" was deliberately
written to be correct.
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
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
3 siblings, 0 replies; 11+ messages in thread
From: Stephen Rothwell @ 2024-10-02 23:39 UTC (permalink / raw)
To: Andrew Morton; +Cc: Brahmajit Das, david, gorcunov, linux-next
[-- Attachment #1: Type: text/plain, Size: 456 bytes --]
Hi Andrew,
On Wed, 2 Oct 2024 14:48:06 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
>
> 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?
But we would probably also have to fix up the other following 2 letter
initializers as well.
--
Cheers,
Stephen Rothwell
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
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
3 siblings, 0 replies; 11+ messages in thread
From: Brahmajit @ 2024-10-04 20:16 UTC (permalink / raw)
To: Andrew Morton; +Cc: david, gorcunov, linux-next
On 02.10.2024 14:48, Andrew Morton wrote:
> "array". But really, just using "mnemonics[]" conveys all we need.
Noted :)
> 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?
Wouldn't that mean we would have to split every element of mnemonics[]
For example, [ilog2(VM_READ)] = "rd" to [ilog2(VM_READ)] = {'r', 'd'}
and so on.
> 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?
>
That does seems correct.
P.S. Sorry for the late reply.
--
Regards,
listout
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
2024-10-02 21:48 ` Andrew Morton
` (2 preceding siblings ...)
2024-10-04 20:16 ` Brahmajit
@ 2024-10-04 21:12 ` Brahmajit
2024-10-04 21:58 ` Andrew Morton
3 siblings, 1 reply; 11+ messages in thread
From: Brahmajit @ 2024-10-04 21:12 UTC (permalink / raw)
To: Andrew Morton, Stephen Rothwell; +Cc: david, gorcunov, linux-next
On 02.10.2024 14:48, Andrew Morton wrote:
> 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?
>
Hi Andrew, Hi Stephen,
With Andrew's suggestion I came up with something like this, would love
some feedback.
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 72f14fd59c2d..c7b6ce4f30c3 100644
--- 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.
*/
@@ -985,13 +992,10 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
seq_puts(m, "VmFlags: ");
for (i = 0; i < BITS_PER_LONG; i++) {
- if (!mnemonics[i][0])
+ if (strcmp(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');
}
--
Regards,
listout
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 1/1] fs: proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
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
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Morton @ 2024-10-04 21:58 UTC (permalink / raw)
To: Brahmajit; +Cc: Stephen Rothwell, david, gorcunov, linux-next
On Sat, 5 Oct 2024 02:42:12 +0530 Brahmajit <brahmajit.xyz@gmail.com> wrote:
> With Andrew's suggestion I came up with something like this, would love
> some feedback.
>
> --- 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.
> */
> @@ -985,13 +992,10 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>
> seq_puts(m, "VmFlags: ");
> for (i = 0; i < BITS_PER_LONG; i++) {
> - if (!mnemonics[i][0])
> + if (strcmp(mnemonics[i], "") == 0)
> continue;
lgtm, except this change isn't needed - testing the 0th char for NULL
is a common idiom.
> - 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');
> }
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/1] fs/proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
2024-10-04 21:58 ` Andrew Morton
@ 2024-10-05 6:37 ` Brahmajit Das
2024-10-08 2:08 ` Andrew Morton
0 siblings, 1 reply; 11+ messages in thread
From: Brahmajit Das @ 2024-10-05 6:37 UTC (permalink / raw)
To: akpm; +Cc: david, gorcunov, linux-next, sfr
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]
...
Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
---
fs/proc/task_mmu.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 72f14fd59c2d..e52bd96137a6 100644
--- 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');
}
--
2.46.2
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/1] fs/proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
2024-10-05 6:37 ` [PATCH v3 1/1] fs/proc: " Brahmajit Das
@ 2024-10-08 2:08 ` Andrew Morton
2024-10-28 8:02 ` Cyrill Gorcunov
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Morton @ 2024-10-08 2:08 UTC (permalink / raw)
To: Brahmajit Das; +Cc: david, gorcunov, linux-next, sfr
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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 1/1] fs/proc: Fix build with GCC 15 due to -Werror=unterminated-string-initialization
2024-10-08 2:08 ` Andrew Morton
@ 2024-10-28 8:02 ` Cyrill Gorcunov
0 siblings, 0 replies; 11+ messages in thread
From: Cyrill Gorcunov @ 2024-10-28 8:02 UTC (permalink / raw)
To: Andrew Morton; +Cc: Brahmajit Das, david, linux-next, sfr
On Mon, Oct 07, 2024 at 07:08:13PM -0700, Andrew Morton wrote:
...
>
> > 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.
Thanks for handling this, Andrew! And sorry for the very late reply :-( I managed to miss
this email somehow, still patch looks ok, thanks!
Cyrill
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-10-28 8:02 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-10-28 8:02 ` Cyrill Gorcunov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).