From 6c3c721275421aa067d4d0018cb95a61277c8a42 Mon Sep 17 00:00:00 2001 From: Michael Holzheu Date: Tue, 5 Sep 2017 13:50:19 +0200 Subject: [PATCH] zgetdump: Fix gcc 7 warning With gcc 7 the compiler checks for sprintf() the maxium possible resulting string based on the used datatypes. Example: struct vol { ... char bus_id[9]; ... } sprintf(vol->bus_id, "0.%x.%04x", ssid, vol_parm->devno); The compiler can prove that "ssid" comes from "u8" and "vol_parm->devno" from "u16". Therefore the resulting maximum string can be 0.ff.ffff which requires 10 bytes. This leads to the following warning: dfi_s390mv.c: In function 'volumes_init': dfi_s390mv.c:243:45: warning: '__builtin___snprintf_chk' output may be truncated before the last format character [-Wformat-truncation=] snprintf(vol->bus_id, sizeof(vol->bus_id), "0.%x.%04x", ssid, ^~~~~~~~~~~ In file included from /usr/include/stdio.h:936:0, from dfi_s390mv.c:15: /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 9 and 10 bytes into a destination of size 9 return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To get rid of the warning use 10 instead of 9 bytes for the bus_id. Signed-off-by: Michael Holzheu --- zdump/dfi_s390mv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zdump/dfi_s390mv.c b/zdump/dfi_s390mv.c index 1da51717..ba8d3cc6 100644 --- a/zdump/dfi_s390mv.c +++ b/zdump/dfi_s390mv.c @@ -81,7 +81,7 @@ struct vol { u64 part_size; u64 mem_start; u64 mem_end; - char bus_id[9]; + char bus_id[10]; u32 nr; u16 blk_size; struct df_s390_dumper dumper;