dm ioctl: Fix compilation warning
authorDamien Le Moal <damien.lemoal@wdc.com>
Thu, 16 Jul 2020 04:38:14 +0000 (13:38 +0900)
committerMike Snitzer <snitzer@redhat.com>
Tue, 4 Aug 2020 19:50:58 +0000 (15:50 -0400)
In retrieve_status(), when copying the target type name in the
target_type string field of struct dm_target_spec, copy at most
DM_MAX_TYPE_NAME - 1 character to avoid the compilation warning:

warning: ‘__builtin_strncpy’ specified bound 16 equals destination
size [-Wstringop-truncation]

when compiling with W-1.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-ioctl.c

index 489935d..5792878 100644 (file)
@@ -1168,7 +1168,7 @@ static void retrieve_status(struct dm_table *table,
                spec->sector_start = ti->begin;
                spec->length = ti->len;
                strncpy(spec->target_type, ti->type->name,
-                       sizeof(spec->target_type));
+                       sizeof(spec->target_type) - 1);
 
                outptr += sizeof(struct dm_target_spec);
                remaining = len - (outptr - outbuf);