s390/tools: fix gcc 8 stringop-truncation warnings
authorVasily Gorbik <gor@linux.ibm.com>
Fri, 29 Jun 2018 15:32:09 +0000 (17:32 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 2 Jul 2018 09:25:05 +0000 (11:25 +0200)
Replace strncpy which has been used to copy a substring into buf
without NUL-termination with memcpy to avoid the following gcc 8
warnings:

arch/s390/tools/gen_opcode_table.c: In function ‘add_to_group.isra.4’:
arch/s390/tools/gen_opcode_table.c:260:2: warning: ‘strncpy’
output may be truncated copying 2 bytes from a string of length 19
[-Wstringop-truncation]
  strncpy(group->opcode, insn->opcode, 2);

In function ‘print_opcode_table’,
    inlined from ‘main’ at arch/s390/tools/gen_opcode_table.c:333:2:
arch/s390/tools/gen_opcode_table.c:286:4: warning: ‘strncpy’
output may be truncated copying 2 bytes from a string of length 19
[-Wstringop-truncation]
    strncpy(opcode, insn->opcode, 2);

Reviewed-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/s390/tools/gen_opcode_table.c

index 259aa06..a1bc02b 100644 (file)
@@ -257,7 +257,7 @@ static void add_to_group(struct gen_opcode *desc, struct insn *insn, int offset)
        if (!desc->group)
                exit(EXIT_FAILURE);
        group = &desc->group[desc->nr_groups - 1];
-       strncpy(group->opcode, insn->opcode, 2);
+       memcpy(group->opcode, insn->opcode, 2);
        group->type = insn->type;
        group->offset = offset;
        group->count = 1;
@@ -283,7 +283,7 @@ static void print_opcode_table(struct gen_opcode *desc)
                        continue;
                add_to_group(desc, insn, offset);
                if (strncmp(opcode, insn->opcode, 2)) {
-                       strncpy(opcode, insn->opcode, 2);
+                       memcpy(opcode, insn->opcode, 2);
                        printf("\t/* %.2s */ \\\n", opcode);
                }
                print_opcode(insn, offset);