Skip to content

Commit 11eceac

Browse files
author
Dave Anderson
committed
Fixes to address several gcc-8.0.1 compiler warnings that are generated
when building with "make warn". The warnings are all false alarm messages of type [-Wformat-overflow=], [-Wformat-truncation=] and [-Wstringop-truncation]; the affected files are extensions.c, task.c, kernel.c, memory.c, remote.c, symbols.c, filesys.c and xen_hyper.c. ([email protected])
1 parent dacfbe8 commit 11eceac

8 files changed

+50
-48
lines changed

extensions.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* extensions.c - core analysis suite
22
*
33
* Copyright (C) 2001, 2002 Mission Critical Linux, Inc.
4-
* Copyright (C) 2002-2013 David Anderson
5-
* Copyright (C) 2002-2013 Red Hat, Inc. All rights reserved.
4+
* Copyright (C) 2002-2013, 2018 David Anderson
5+
* Copyright (C) 2002-2013, 2018 Red Hat, Inc. All rights reserved.
66
*
77
* This program is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -363,7 +363,7 @@ preload_extensions(void)
363363
DIR *dirp;
364364
struct dirent *dp;
365365
char dirbuf[BUFSIZE];
366-
char filename[BUFSIZE];
366+
char filename[BUFSIZE*2];
367367
int found;
368368

369369
if (!get_extensions_directory(dirbuf))

filesys.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,10 @@ show_mounts(ulong one_vfsmount, int flags, struct task_context *namespace_contex
13661366
long s_dirty;
13671367
ulong devp, dirp, sbp, dirty, type, name;
13681368
struct list_data list_data, *ld;
1369-
char buf1[BUFSIZE];
1369+
char buf1[BUFSIZE*2];
13701370
char buf2[BUFSIZE];
13711371
char buf3[BUFSIZE];
1372-
char buf4[BUFSIZE];
1372+
char buf4[BUFSIZE/2];
13731373
ulong *dentry_list, *dp, *mntlist;
13741374
ulong *vfsmnt;
13751375
char *vfsmount_buf, *super_block_buf, *mount_buf;
@@ -1494,8 +1494,8 @@ show_mounts(ulong one_vfsmount, int flags, struct task_context *namespace_contex
14941494
KVADDR, &name, sizeof(void *),
14951495
"file_system_type name", FAULT_ON_ERROR);
14961496

1497-
if (read_string(name, buf1, BUFSIZE-1))
1498-
sprintf(buf3, "%-6s ", buf1);
1497+
if (read_string(name, buf4, BUFSIZE-1))
1498+
sprintf(buf3, "%-6s ", buf4);
14991499
else
15001500
sprintf(buf3, "unknown ");
15011501

@@ -2389,7 +2389,7 @@ open_files_dump(ulong task, int flags, struct reference *ref)
23892389
char buf2[BUFSIZE];
23902390
char buf3[BUFSIZE];
23912391
char buf4[BUFSIZE];
2392-
char root_pwd[BUFSIZE];
2392+
char root_pwd[BUFSIZE*4];
23932393
int root_pwd_printed = 0;
23942394
int file_dump_flags = 0;
23952395

@@ -3082,7 +3082,7 @@ get_pathname(ulong dentry, char *pathname, int length, int full, ulong vfsmnt)
30823082
break;
30833083

30843084
if (tmp_dentry != dentry) {
3085-
strncpy(tmpname, pathname, BUFSIZE);
3085+
strncpy(tmpname, pathname, BUFSIZE-1);
30863086
if (strlen(tmpname) + d_name_len < BUFSIZE) {
30873087
if ((d_name_len > 1 || !STREQ(buf, "/")) &&
30883088
!STRNEQ(tmpname, "/")) {
@@ -3613,8 +3613,8 @@ get_live_memory_source(void)
36133613
{
36143614
FILE *pipe;
36153615
char buf[BUFSIZE];
3616-
char modname1[BUFSIZE];
3617-
char modname2[BUFSIZE];
3616+
char modname1[BUFSIZE/2];
3617+
char modname2[BUFSIZE/2];
36183618
char *name;
36193619
int use_module, crashbuiltin;
36203620
struct stat stat1, stat2;

kernel.c

+19-17
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ kernel_init()
253253
kt->utsname.domainname : "(not printable)");
254254
}
255255

256-
strncpy(buf, kt->utsname.release, MIN(strlen(kt->utsname.release), 65));
256+
strncpy(buf, kt->utsname.release, 65);
257+
if (buf[64])
258+
buf[64] = NULLCHAR;
257259
if (ascii_string(kt->utsname.release)) {
258260
char separator;
259261

@@ -1258,11 +1260,11 @@ verify_namelist()
12581260
{
12591261
int i;
12601262
char command[BUFSIZE];
1261-
char buffer[BUFSIZE];
1262-
char buffer2[BUFSIZE];
1263-
char buffer3[BUFSIZE];
1264-
char buffer4[BUFSIZE];
1265-
char buffer5[BUFSIZE];
1263+
char buffer[BUFSIZE/2];
1264+
char buffer2[BUFSIZE/2];
1265+
char buffer3[BUFSIZE/2];
1266+
char buffer4[BUFSIZE/2];
1267+
char buffer5[BUFSIZE*2];
12661268
char *p1;
12671269
FILE *pipe;
12681270
int found;
@@ -1379,12 +1381,12 @@ verify_namelist()
13791381
else
13801382
sprintf(buffer, "%s", ACTIVE() ? "live system" : pc->dumpfile);
13811383

1382-
sprintf(buffer2, " %s is %s -- %s is %s\n",
1384+
sprintf(buffer5, " %s is %s -- %s is %s\n",
13831385
namelist, namelist_smp ? "SMP" : "not SMP",
13841386
buffer, target_smp ? "SMP" : "not SMP");
13851387

13861388
error(INFO, "incompatible arguments: %s%s",
1387-
strlen(buffer2) > 48 ? "\n " : "", buffer2);
1389+
strlen(buffer5) > 48 ? "\n " : "", buffer5);
13881390

13891391
program_usage(SHORT_FORM);
13901392
}
@@ -1396,7 +1398,7 @@ static void
13961398
source_tree_init(void)
13971399
{
13981400
FILE *pipe;
1399-
char command[BUFSIZE];
1401+
char command[BUFSIZE*2];
14001402
char buf[BUFSIZE];
14011403

14021404
if (!is_directory(kt->source_tree)) {
@@ -1429,7 +1431,7 @@ list_source_code(struct gnu_request *req, int count_entered)
14291431
int argc, line, last, done, assembly;
14301432
char buf1[BUFSIZE];
14311433
char buf2[BUFSIZE];
1432-
char buf3[BUFSIZE];
1434+
char buf3[BUFSIZE*2];
14331435
char file[BUFSIZE];
14341436
char *argv[MAXARGS];
14351437
struct syment *sp;
@@ -2555,7 +2557,7 @@ cmd_bt(void)
25552557
} else {
25562558
bt->flags |= BT_CPUMASK;
25572559
BZERO(arg_buf, BUFSIZE);
2558-
strncpy(arg_buf, optarg, strlen(optarg));
2560+
strcpy(arg_buf, optarg);
25592561
cpus = get_cpumask_buf();
25602562
}
25612563
break;
@@ -4748,7 +4750,7 @@ find_module_objfile(char *modref, char *filename, char *tree)
47484750
retbuf = module_objfile_search(modref, filename, tree);
47494751

47504752
if (!retbuf) {
4751-
strncpy(tmpref, modref, BUFSIZE);
4753+
strncpy(tmpref, modref, BUFSIZE-1);
47524754
for (c = 0; c < BUFSIZE && tmpref[c]; c++)
47534755
if (tmpref[c] == '_')
47544756
tmpref[c] = '-';
@@ -6244,7 +6246,7 @@ cmd_irq(void)
62446246
} else {
62456247
choose_cpu = 1;
62466248
BZERO(arg_buf, BUFSIZE);
6247-
strncpy(arg_buf, optarg, strlen(optarg));
6249+
strcpy(arg_buf, optarg);
62486250
}
62496251
break;
62506252

@@ -6988,8 +6990,8 @@ generic_get_irq_affinity(int irq)
69886990
BZERO(buf, BUFSIZE);
69896991
if (read_string(name, buf, BUFSIZE-1)) {
69906992
if (strlen(name_buf) != 0)
6991-
strncat(name_buf, ",", 2);
6992-
strncat(name_buf, buf, strlen(buf));
6993+
strcat(name_buf, ",");
6994+
strcat(name_buf, buf);
69936995
}
69946996

69956997
readmem(action+OFFSET(irqaction_next), KVADDR,
@@ -7128,8 +7130,8 @@ generic_show_interrupts(int irq, ulong *cpus)
71287130
BZERO(buf2, BUFSIZE);
71297131
if (read_string(name, buf2, BUFSIZE-1)) {
71307132
if (strlen(name_buf) != 0)
7131-
strncat(name_buf, ",", 2);
7132-
strncat(name_buf, buf2, strlen(buf2));
7133+
strcat(name_buf, ",");
7134+
strcat(name_buf, buf2);
71337135
}
71347136

71357137
readmem(action+OFFSET(irqaction_next), KVADDR,

memory.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ display_memory(ulonglong addr, long count, ulong flag, int memtype, void *opt)
14381438
char ch;
14391439
int linelen;
14401440
char buf[BUFSIZE];
1441-
char slab[BUFSIZE];
1441+
char slab[BUFSIZE/2];
14421442
int ascii_start;
14431443
ulong error_handle;
14441444
char *hex_64_fmt = BITS32() ? "%.*llx " : "%.*lx ";
@@ -1952,7 +1952,7 @@ char *
19521952
format_stack_entry(struct bt_info *bt, char *retbuf, ulong value, ulong limit)
19531953
{
19541954
char buf[BUFSIZE];
1955-
char slab[BUFSIZE];
1955+
char slab[BUFSIZE/2];
19561956

19571957
if (BITS32()) {
19581958
if ((bt->flags & BT_FULL_SYM_SLAB) && accessible(value)) {
@@ -4014,7 +4014,7 @@ vm_area_page_dump(ulong vma,
40144014
int display;
40154015
char buf1[BUFSIZE];
40164016
char buf2[BUFSIZE];
4017-
char buf3[BUFSIZE];
4017+
char buf3[BUFSIZE*2];
40184018
char buf4[BUFSIZE];
40194019

40204020
if (mm == symbol_value("init_mm"))

remote.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* remote.c - core analysis suite
22
*
33
* Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
4-
* Copyright (C) 2002, 2003, 2004, 2005, 2009, 2011 David Anderson
5-
* Copyright (C) 2002, 2003, 2004, 2005, 2009, 2011 Red Hat, Inc. All rights reserved.
4+
* Copyright (C) 2002, 2003, 2004, 2005, 2009, 2011, 2018 David Anderson
5+
* Copyright (C) 2002, 2003, 2004, 2005, 2009, 2011, 2018 Red Hat, Inc. All rights reserved.
66
*
77
* This program is free software; you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -2759,7 +2759,7 @@ identical_namelist(char *file, struct remote_file *rfp)
27592759
long csum;
27602760
char sendbuf[BUFSIZE];
27612761
char recvbuf[BUFSIZE];
2762-
char readbuf[BUFSIZE];
2762+
char readbuf[BUFSIZE*2];
27632763

27642764
if (stat(file, &sbuf) < 0)
27652765
return FALSE;
@@ -3264,7 +3264,7 @@ static int
32643264
copy_remote_file(struct remote_file *rfp, int fd, char *file, char *ttystr)
32653265
{
32663266
char sendbuf[BUFSIZE];
3267-
char recvbuf[BUFSIZE];
3267+
char recvbuf[BUFSIZE*2];
32683268
char readbuf[READBUFSIZE];
32693269
char *bufptr;
32703270
long pct, last;
@@ -3399,7 +3399,7 @@ copy_remote_gzip_file(struct remote_file *rfp, char *file, char *ttystr)
33993399
}
34003400
if (STRNEQ(bufptr, DONEMSG) ||
34013401
STRNEQ(bufptr, DATAMSG)) {
3402-
strncpy(gziphdr, bufptr, DATA_HDRSIZE);
3402+
BCOPY(bufptr, gziphdr, DATA_HDRSIZE);
34033403
if (CRASHDEBUG(1))
34043404
fprintf(fp,
34053405
"copy_remote_gzip_file: [%s]\n",
@@ -3647,7 +3647,7 @@ remote_memory_dump(int verbose)
36473647
}
36483648
if (STRNEQ(bufptr, DONEMSG) ||
36493649
STRNEQ(bufptr, DATAMSG)) {
3650-
strncpy(datahdr, bufptr, DATA_HDRSIZE);
3650+
BCOPY(bufptr, datahdr, DATA_HDRSIZE);
36513651
if (CRASHDEBUG(1))
36523652
fprintf(fp,
36533653
"remote_memory_dump: [%s]\n",
@@ -3788,7 +3788,7 @@ int
37883788
remote_execute(void)
37893789
{
37903790
char command[BUFSIZE];
3791-
char sendbuf[BUFSIZE];
3791+
char sendbuf[BUFSIZE*2];
37923792
char readbuf[READBUFSIZE];
37933793
char datahdr[DATA_HDRSIZE];
37943794
char *bufptr, *p1;
@@ -3833,7 +3833,7 @@ remote_execute(void)
38333833
}
38343834
if (STRNEQ(bufptr, DONEMSG) ||
38353835
STRNEQ(bufptr, DATAMSG)) {
3836-
strncpy(datahdr, bufptr, DATA_HDRSIZE);
3836+
BCOPY(bufptr, datahdr, DATA_HDRSIZE);
38373837
if (CRASHDEBUG(1))
38383838
fprintf(fp,
38393839
"remote_execute: [%s]\n",

symbols.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1364,9 +1364,9 @@ store_module_symbols_v1(ulong total, int mods_installed)
13641364
struct module_symbol *modsym;
13651365
struct load_module *lm;
13661366
char buf1[BUFSIZE];
1367-
char buf2[BUFSIZE];
1367+
char buf2[BUFSIZE*2];
13681368
char name[BUFSIZE];
1369-
char rodata[BUFSIZE];
1369+
char rodata[BUFSIZE*2];
13701370
char *strbuf, *modbuf, *modsymbuf;
13711371
struct syment *sp;
13721372
ulong first, last;
@@ -1432,7 +1432,7 @@ store_module_symbols_v1(ulong total, int mods_installed)
14321432
error(INFO,
14331433
"module name greater than MAX_MOD_NAME: %s\n",
14341434
name);
1435-
strncpy(lm->mod_name, name, MAX_MOD_NAME-1);
1435+
BCOPY(name, lm->mod_name, MAX_MOD_NAME-1);
14361436
}
14371437

14381438
lm->mod_flags = MOD_EXT_SYMS;
@@ -5932,7 +5932,7 @@ static int
59325932
dereference_pointer(ulong addr, struct datatype_member *dm, ulong flags)
59335933
{
59345934
char buf1[BUFSIZE];
5935-
char buf2[BUFSIZE];
5935+
char buf2[BUFSIZE*2];
59365936
char *typeptr, *member, *charptr, *voidptr, *p1, *sym;
59375937
int found, ptrptr, funcptr, typedef_is_ptr, use_symbol;
59385938
ulong target, value;
@@ -11419,7 +11419,7 @@ add_symbol_file_kallsyms(struct load_module *lm, struct gnu_request *req)
1141911419
ulong vaddr, array_entry, attribute, owner, name, address;
1142011420
long name_type;
1142111421
char buf[BUFSIZE];
11422-
char section_name[BUFSIZE];
11422+
char section_name[BUFSIZE/2];
1142311423
ulong section_vaddr;
1142411424

1142511425
#if defined(GDB_5_3) || defined(GDB_6_0) || defined(GDB_6_1)
@@ -11578,7 +11578,7 @@ add_symbol_file_kallsyms(struct load_module *lm, struct gnu_request *req)
1157811578
}
1157911579
}
1158011580

11581-
BZERO(section_name, BUFSIZE);
11581+
BZERO(section_name, BUFSIZE/2);
1158211582
if (!read_string(name, section_name, 32)) {
1158311583
done = TRUE;
1158411584
retval = FALSE;
@@ -11606,7 +11606,7 @@ add_symbol_file_kallsyms(struct load_module *lm, struct gnu_request *req)
1160611606
buflen *= 2;
1160711607
}
1160811608
shift_string_right(req->buf, strlen(buf));
11609-
strncpy(req->buf, buf, strlen(buf));
11609+
BCOPY(buf, req->buf, strlen(buf));
1161011610
retval = TRUE;
1161111611
} else {
1161211612
sprintf(buf, " -s %s 0x%lx", section_name, section_vaddr);

task.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -8325,7 +8325,7 @@ cmd_runq(void)
83258325
} else {
83268326
pc->curcmd_flags |= CPUMASK;
83278327
BZERO(arg_buf, BUFSIZE);
8328-
strncpy(arg_buf, optarg, strlen(optarg));
8328+
strcpy(arg_buf, optarg);
83298329
cpus = get_cpumask_buf();
83308330
make_cpumask(arg_buf, cpus, FAULT_ON_ERROR, NULL);
83318331
pc->curcmd_private = (ulong)cpus;

xen_hyper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ xen_hyper_schedule_init(void)
534534
error(FATAL, "cannot malloc scheduler_name space.\n");
535535
}
536536
BZERO(xhscht->name, strlen(buf) + 1);
537-
strncpy(xhscht->name, buf, strlen(buf));
537+
BCOPY(buf, xhscht->name, strlen(buf));
538538
break;
539539
}
540540
addr += sizeof(long) * nr_schedulers;

0 commit comments

Comments
 (0)