mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
lscss: Get rid of gcc 7 buffer truncation warnings
With gcc 7 we get warnings for code like the following:
44 #define MAX_BUFFER_SIZE_FOR_SUBCHANNEL_ATTRIBUTES 37
406 char buf[MAX_BUFFER_SIZE_FOR_SUBCHANNEL_ATTRIBUTES];
416 device = de_vec[0]->d_name;
417 snprintf(buf, sizeof(buf), "%s", device);
$ grep -r 'd_name\[' /usr/include/
/usr/include/bits/dirent.h: char d_name[256];
The compiler assumes that d_name can be up to 255 characters. Therefore
it produces the following warning:
CC zconf/css/lscss.o
lscss.c: In function 'print_sch_io':
lscss.c:417:31: warning: '%s' directive output may be truncated writing
up to 255 bytes into a region of size 37 [-Wformat-truncation=]
snprintf(buf, sizeof(buf), "%s", device);
^~
In file included from /usr/include/stdio.h:936:0,
from lscss.c:10:
/usr/include/bits/stdio2.h:64:10: note: '__builtin_snprintf' output
between 1 and 256 bytes into a destination of size 37
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fix this and use larger buffer sizes to keep gcc quiet.
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
This commit is contained in:
@@ -41,8 +41,7 @@
|
||||
#define UUID_FORMAT "^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$"
|
||||
|
||||
/* Misc constants */
|
||||
#define MAX_BUFFER_SIZE_FOR_SUBCHANNEL_ATTRIBUTES 37
|
||||
#define MAX_BUFFER_SIZE_FOR_DEVICE_ATTRIBUTES 16
|
||||
#define MAX_BUF_SIZE 256
|
||||
#define PREFIX_ID_LENGTH 4
|
||||
#define SHORT_ID_LENGTH 4
|
||||
#define CHPIDS_SEGMENT_LENGTH 8
|
||||
@@ -310,8 +309,8 @@ static bool in_devtypes_list(char *dtype)
|
||||
*/
|
||||
static int fill_device_info(struct util_rec *rec, char *path, char *device)
|
||||
{
|
||||
char buf[MAX_BUFFER_SIZE_FOR_DEVICE_ATTRIBUTES];
|
||||
unsigned long int val_ul;
|
||||
char buf[MAX_BUF_SIZE];
|
||||
|
||||
if (!path || !device) {
|
||||
if (cmd.opt_devtype && cmd.dev_count > 0)
|
||||
@@ -403,7 +402,7 @@ static bool is_sch_vfio(char *path)
|
||||
*/
|
||||
static int fill_vfio_devid(struct util_rec *rec, char *path)
|
||||
{
|
||||
char *device, buf[MAX_BUFFER_SIZE_FOR_SUBCHANNEL_ATTRIBUTES];
|
||||
char *device, buf[MAX_BUF_SIZE];
|
||||
struct dirent **de_vec;
|
||||
int count;
|
||||
|
||||
@@ -433,7 +432,7 @@ static int fill_vfio_devid(struct util_rec *rec, char *path)
|
||||
*/
|
||||
static int fill_io_devid(struct util_rec *rec, char *path)
|
||||
{
|
||||
char *device, buf[MAX_BUFFER_SIZE_FOR_SUBCHANNEL_ATTRIBUTES];
|
||||
char *device, buf[MAX_BUF_SIZE];
|
||||
struct dirent **de_vec;
|
||||
int count;
|
||||
|
||||
@@ -479,8 +478,8 @@ static int fill_io_devid(struct util_rec *rec, char *path)
|
||||
*/
|
||||
static void print_sch_io(struct util_rec *rec, char *path, char *sch_dir)
|
||||
{
|
||||
char buf[MAX_BUFFER_SIZE_FOR_SUBCHANNEL_ATTRIBUTES];
|
||||
unsigned int pim, pam, pom;
|
||||
char buf[MAX_BUF_SIZE];
|
||||
|
||||
/* Fill in subchannel ID */
|
||||
if (cmd.opt_short) {
|
||||
@@ -560,7 +559,7 @@ static void print_sch_io(struct util_rec *rec, char *path, char *sch_dir)
|
||||
*/
|
||||
static void print_sch_chsc(struct util_rec *rec, char *sch_dir)
|
||||
{
|
||||
char buf[MAX_BUFFER_SIZE_FOR_DEVICE_ATTRIBUTES];
|
||||
char buf[MAX_BUF_SIZE];
|
||||
|
||||
/* Skip entry if devrange or devtype option is active */
|
||||
if (cmd.opt_devrange && cmd.rng_count > 0)
|
||||
@@ -596,7 +595,7 @@ static void print_sch_chsc(struct util_rec *rec, char *sch_dir)
|
||||
*/
|
||||
static void print_sch_eadm(struct util_rec *rec, char *sch_dir)
|
||||
{
|
||||
char buf[MAX_BUFFER_SIZE_FOR_DEVICE_ATTRIBUTES];
|
||||
char buf[MAX_BUF_SIZE];
|
||||
|
||||
/* Skip entry if devrange or devtype option is active */
|
||||
if (cmd.opt_devrange && cmd.rng_count > 0)
|
||||
@@ -632,7 +631,7 @@ static void print_sch_eadm(struct util_rec *rec, char *sch_dir)
|
||||
*/
|
||||
static void print_defunct_devices(struct util_rec *rec, char *path)
|
||||
{
|
||||
char *device, buf[MAX_BUFFER_SIZE_FOR_DEVICE_ATTRIBUTES];
|
||||
char *device, buf[MAX_BUF_SIZE];
|
||||
struct dirent **de_vec;
|
||||
int i, count;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user