s390/tape: fix gcc 8 stringop-truncation warning
authorVasily Gorbik <gor@linux.ibm.com>
Thu, 28 Jun 2018 11:28:37 +0000 (13:28 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 2 Jul 2018 09:25:03 +0000 (11:25 +0200)
Replace strncpy which is used to deliberately avoid string NUL-termination
with memcpy. This allows to get rid of gcc 8 stringop-truncation warning:

    inlined from 'ext_to_int_kekl' at drivers/s390/char/tape_3590.c:123:2:
./include/linux/string.h:246:9: warning: '__builtin_strncpy'
output may be truncated copying 64 bytes from a string of length 64
[-Wstringop-truncation]

Also replaces "for" loop on memset.

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>
drivers/s390/char/tape_3590.c

index 37e65a05517f50606f73db539e0871e76452d142..cdcde18e72203eeeb07e975adb5aaa8ca0258199 100644 (file)
@@ -113,16 +113,16 @@ static int crypt_enabled(struct tape_device *device)
 static void ext_to_int_kekl(struct tape390_kekl *in,
                            struct tape3592_kekl *out)
 {
-       int i;
+       int len;
 
        memset(out, 0, sizeof(*out));
        if (in->type == TAPE390_KEKL_TYPE_HASH)
                out->flags |= 0x40;
        if (in->type_on_tape == TAPE390_KEKL_TYPE_HASH)
                out->flags |= 0x80;
-       strncpy(out->label, in->label, 64);
-       for (i = strlen(in->label); i < sizeof(out->label); i++)
-               out->label[i] = ' ';
+       len = min(sizeof(out->label), strlen(in->label));
+       memcpy(out->label, in->label, len);
+       memset(out->label + len, ' ', sizeof(out->label) - len);
        ASCEBC(out->label, sizeof(out->label));
 }