* [PATCH 1/1] cachefiles: fix build with GCC 15
@ 2025-01-21 9:15 Brahmajit Das
2025-01-21 22:19 ` David Laight
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Brahmajit Das @ 2025-01-21 9:15 UTC (permalink / raw)
To: dhowells; +Cc: netfs, linux-kernel
While building with GCC 15 I noticed these build error
fs/cachefiles/key.c:12:9: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
12 | "0123456789" /* 0 - 9 */
| ^~~~~~~~~~~~
cc1: all warnings being treated as errors
This due to GCC 15 having enabled -Wunterminated-string-initialization
by default[0]. Separating each characters to ensure NUL termination of
char array.
[0]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization
Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
---
fs/cachefiles/key.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/fs/cachefiles/key.c b/fs/cachefiles/key.c
index bf935e25bdbe..555a0ec9eff4 100644
--- a/fs/cachefiles/key.c
+++ b/fs/cachefiles/key.c
@@ -8,12 +8,14 @@
#include <linux/slab.h>
#include "internal.h"
-static const char cachefiles_charmap[64] =
- "0123456789" /* 0 - 9 */
- "abcdefghijklmnopqrstuvwxyz" /* 10 - 35 */
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 36 - 61 */
- "_-" /* 62 - 63 */
- ;
+static const char cachefiles_charmap[64] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', /* 0 - 9 */
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 10 - 35 */
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', /* 10 - 35 */
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', /* 36 - 61 */
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', /* 36 - 61 */
+ '_', '-' /* 62 - 63 */
+};
static const char cachefiles_filecharmap[256] = {
/* we skip space and tab and control chars */
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 1/1] cachefiles: fix build with GCC 15
2025-01-21 9:15 [PATCH 1/1] cachefiles: fix build with GCC 15 Brahmajit Das
@ 2025-01-21 22:19 ` David Laight
2025-01-21 22:41 ` David Laight
2025-01-22 9:03 ` [PATCH v2 " Brahmajit Das
2025-02-10 15:20 ` David Howells
2 siblings, 1 reply; 5+ messages in thread
From: David Laight @ 2025-01-21 22:19 UTC (permalink / raw)
To: Brahmajit Das; +Cc: dhowells, netfs, linux-kernel
On Tue, 21 Jan 2025 14:45:30 +0530
Brahmajit Das <brahmajit.xyz@gmail.com> wrote:
> While building with GCC 15 I noticed these build error
>
> fs/cachefiles/key.c:12:9: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> 12 | "0123456789" /* 0 - 9 */
> | ^~~~~~~~~~~~
> cc1: all warnings being treated as errors
>
> This due to GCC 15 having enabled -Wunterminated-string-initialization
> by default[0]. Separating each characters to ensure NUL termination of
> char array.
>
> [0]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization
>
> Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
> ---
> fs/cachefiles/key.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/fs/cachefiles/key.c b/fs/cachefiles/key.c
> index bf935e25bdbe..555a0ec9eff4 100644
> --- a/fs/cachefiles/key.c
> +++ b/fs/cachefiles/key.c
> @@ -8,12 +8,14 @@
> #include <linux/slab.h>
> #include "internal.h"
>
> -static const char cachefiles_charmap[64] =
> - "0123456789" /* 0 - 9 */
> - "abcdefghijklmnopqrstuvwxyz" /* 10 - 35 */
> - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 36 - 61 */
> - "_-" /* 62 - 63 */
> - ;
> +static const char cachefiles_charmap[64] = {
> + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', /* 0 - 9 */
> + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 10 - 35 */
> + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', /* 10 - 35 */
> + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', /* 36 - 61 */
> + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', /* 36 - 61 */
> + '_', '-' /* 62 - 63 */
> +};
That is just horrid.
I think there is a attribute that stops the warning.
Or just convert to unsigned char [].
David
>
> static const char cachefiles_filecharmap[256] = {
> /* we skip space and tab and control chars */
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 1/1] cachefiles: fix build with GCC 15
2025-01-21 22:19 ` David Laight
@ 2025-01-21 22:41 ` David Laight
0 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2025-01-21 22:41 UTC (permalink / raw)
To: Brahmajit Das; +Cc: dhowells, netfs, linux-kernel
On Tue, 21 Jan 2025 22:19:11 +0000
David Laight <david.laight.linux@gmail.com> wrote:
> On Tue, 21 Jan 2025 14:45:30 +0530
> Brahmajit Das <brahmajit.xyz@gmail.com> wrote:
>
> > While building with GCC 15 I noticed these build error
> >
> > fs/cachefiles/key.c:12:9: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> > 12 | "0123456789" /* 0 - 9 */
> > | ^~~~~~~~~~~~
> > cc1: all warnings being treated as errors
> >
> > This due to GCC 15 having enabled -Wunterminated-string-initialization
> > by default[0]. Separating each characters to ensure NUL termination of
> > char array.
> >
> > [0]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization
> >
> > Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
> > ---
> > fs/cachefiles/key.c | 14 ++++++++------
> > 1 file changed, 8 insertions(+), 6 deletions(-)
> >
> > diff --git a/fs/cachefiles/key.c b/fs/cachefiles/key.c
> > index bf935e25bdbe..555a0ec9eff4 100644
> > --- a/fs/cachefiles/key.c
> > +++ b/fs/cachefiles/key.c
> > @@ -8,12 +8,14 @@
> > #include <linux/slab.h>
> > #include "internal.h"
> >
> > -static const char cachefiles_charmap[64] =
> > - "0123456789" /* 0 - 9 */
> > - "abcdefghijklmnopqrstuvwxyz" /* 10 - 35 */
> > - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 36 - 61 */
> > - "_-" /* 62 - 63 */
> > - ;
> > +static const char cachefiles_charmap[64] = {
> > + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', /* 0 - 9 */
> > + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', /* 10 - 35 */
> > + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', /* 10 - 35 */
> > + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', /* 36 - 61 */
> > + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', /* 36 - 61 */
> > + '_', '-' /* 62 - 63 */
> > +};
>
> That is just horrid.
> I think there is a attribute that stops the warning.
> Or just convert to unsigned char [].
Bah, neither works, but see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
and https://gcc.gnu.org/pipermail/gcc-patches/2024-December/671714.html
If/when applied adding __attribute__((nonstring)) will disable the warning.
In this case just changing the [64] to [65] will do no harm.
But perhaps the warning should just be disabled for now.
David
>
> David
>
>
> >
> > static const char cachefiles_filecharmap[256] = {
> > /* we skip space and tab and control chars */
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/1] cachefiles: fix build with GCC 15
2025-01-21 9:15 [PATCH 1/1] cachefiles: fix build with GCC 15 Brahmajit Das
2025-01-21 22:19 ` David Laight
@ 2025-01-22 9:03 ` Brahmajit Das
2025-02-10 15:20 ` David Howells
2 siblings, 0 replies; 5+ messages in thread
From: Brahmajit Das @ 2025-01-22 9:03 UTC (permalink / raw)
To: brahmajit.xyz, david.laight.linux; +Cc: dhowells, linux-kernel, netfs
Building with GCC 15 results in the following error
fs/cachefiles/key.c:12:9: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
12 | "0123456789" /* 0 - 9 */
| ^~~~~~~~~~~~
cc1: all warnings being treated as errors
This due to GCC 15 having enabled -Wunterminated-string-initialization
by default[0]. Here we're increasing the size of cachefiles_charmap from
64 to 65 to ensure space for NUL. Unfortunately using
__attribute__((nonstring)) or converting to unsigned char [] didn't help
in this case (thanks to David Laight <david.laight.linux@gmail.com>).
Please also refer:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178, and
https://gcc.gnu.org/pipermail/gcc-patches/2024-December/671714.html
[0]:
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization
Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
---
fs/cachefiles/key.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/cachefiles/key.c b/fs/cachefiles/key.c
index bf935e25bdbe..a75ea693f649 100644
--- a/fs/cachefiles/key.c
+++ b/fs/cachefiles/key.c
@@ -8,7 +8,7 @@
#include <linux/slab.h>
#include "internal.h"
-static const char cachefiles_charmap[64] =
+static const char cachefiles_charmap[65] =
"0123456789" /* 0 - 9 */
"abcdefghijklmnopqrstuvwxyz" /* 10 - 35 */
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 36 - 61 */
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 1/1] cachefiles: fix build with GCC 15
2025-01-21 9:15 [PATCH 1/1] cachefiles: fix build with GCC 15 Brahmajit Das
2025-01-21 22:19 ` David Laight
2025-01-22 9:03 ` [PATCH v2 " Brahmajit Das
@ 2025-02-10 15:20 ` David Howells
2 siblings, 0 replies; 5+ messages in thread
From: David Howells @ 2025-02-10 15:20 UTC (permalink / raw)
To: Brahmajit Das; +Cc: dhowells, david.laight.linux, linux-kernel, netfs
Brahmajit Das <brahmajit.xyz@gmail.com> wrote:
> Building with GCC 15 results in the following error
>
> fs/cachefiles/key.c:12:9: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization]
> 12 | "0123456789" /* 0 - 9 */
> | ^~~~~~~~~~~~
> cc1: all warnings being treated as errors
>
> This due to GCC 15 having enabled -Wunterminated-string-initialization
> by default[0]. Here we're increasing the size of cachefiles_charmap from
> 64 to 65 to ensure space for NUL. Unfortunately using
> __attribute__((nonstring)) or converting to unsigned char [] didn't help
> in this case (thanks to David Laight <david.laight.linux@gmail.com>).
>
> Please also refer:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178, and
> https://gcc.gnu.org/pipermail/gcc-patches/2024-December/671714.html
>
> [0]:
> https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wno-unterminated-string-initialization
>
> Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
Acked-by: David Howells <dhowells@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-10 15:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-21 9:15 [PATCH 1/1] cachefiles: fix build with GCC 15 Brahmajit Das
2025-01-21 22:19 ` David Laight
2025-01-21 22:41 ` David Laight
2025-01-22 9:03 ` [PATCH v2 " Brahmajit Das
2025-02-10 15:20 ` David Howells
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).