s390/dis: Mark non-NUL-terminated character arrays with __nonstring
Heiko Carstens
maintainerPATCH 1/1 s390/dis: Mark non-NUL-terminated character arrays with __nonstring
With [1] the generated string initializers were changed to use an array instead of a non-NUL-terminated string. The reason was that GCC 15 warns about string initializers that truncate the NUL terminator with -Wunterminated-string-initialization.
The better solution is to use the __nonstring annotation, which exists to deal exactly with this problem. Therefore use it and basically revert [1] in order to generate more readable initializers:
Before:
[LONG_INSN_ALGHSIK] = { 'a', 'l', 'g', 'h', 's', 'i', 'k', },
After:
[LONG_INSN_ALGHSIK] = "alghsik",
[1] commit 7cbae7ea3de5 ("s390/tools: Use array instead of string initializer")
--- arch/s390/kernel/dis.c | 4 ++-- arch/s390/tools/gen_opcode_table.c | 23 ++++------------------- 2 files changed, 6 insertions(+), 21 deletions(-)
arch/s390/kernel/dis.c +2 -2
@@ -51,7 +51,7 @@ struct s390_operand { struct s390_insn { union { - const char name[5]; + const char name[5] __nonstring; struct { unsigned char zero; unsigned int offset;
@@ -340,7 +340,7 @@ static const unsigned char formats[][6] = { [INSTR_VSI_URDV] = { V_32, D_20, B_16, U8_8, 0, 0 }, }; -static char long_insn_name[][7 ] =LONG_INSN_INITIALIZER ; +static char long_insn_name[][7] __nonstring = LONG_INSN_INITIALIZER;static struct s390_insn opcode[] =OPCODE_TABLE_INITIALIZER ;static struct s390_opcode_offset opcode_offset[] =OPCODE_OFFSET_INITIALIZER ;
arch/s390/tools/gen_opcode_table.c +4 -19
@@ -201,17 +201,6 @@ static int cmp_long_insn(const void *a, const void *b)return strcmp (((struct insn *)a)->name, ((struct insn *)b)->name); } -static void print_insn_name (const char *name) -{ -size_t i, len; - - len =strlen (name); -printf ("{" ); -for (i =0 ; i < len; i++) -printf (" \'%c\'," , name[i]); -printf (" }" ); -} -static void print_long_insn (struct gen_opcode *desc) {struct insn *insn;
@@ -234,9 +223,7 @@ static void print_long_insn(struct gen_opcode *desc) insn = &desc->insn[i];if (insn->name_len <6 )continue ; -printf ("\t[LONG_INSN_%s] = " , insn->upper); -print_insn_name (insn->name); -printf (", \\\n" ); +printf ("\t[LONG_INSN_%s] = \"%s\", \\\n" , insn->upper, insn->name); }printf ("}\n\n" ); }
@@ -249,12 +236,10 @@ static void print_opcode(struct insn *insn, int nr)if (insn->type->byte !=0 ) opcode +=2 ;printf ("\t[%4d] = { .opfrag = 0x%s, .format = INSTR_%s, " , nr, opcode, insn->format); -if (insn->name_len <6 ) { -printf (".name = " ); -print_insn_name (insn->name); - }else { +if (insn->name_len <6 ) +printf (".name = \"%s\"" , insn->name); +else printf (".offset = LONG_INSN_%s" , insn->upper); - }printf (" }, \\\n" ); }
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines
With [1] the generated string initializers were changed to use an array instead of a non-NUL-terminated string. The reason was that GCC 15 warns about string initializers that truncate the NUL terminator with -Wunterminated-string-initialization.
The better solution is to use the
__nonstringannotation, which exists to deal exactly with this problem. Therefore use it and basically revert [1] in order to generate more readable initializers:Before:
[LONG_INSN_ALGHSIK] = { 'a', 'l', 'g', 'h', 's', 'i', 'k', },
Quoted 6 lines
After:
[LONG_INSN_ALGHSIK] = "alghsik",[1] commit
7cbae7ea3de5("s390/tools: Use array instead of string initializer")Signed-off-by Heiko Carstens <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1