Fix const-correctness issues uncovered by gcc -Wwrite-strings
* defs.h (struct xlat): Add const qualifier to the field of type "char *". (set_sortby, qualify, printnum, printnum_int): Add const qualifier to arguments of type "char *". * count.c (set_sortby): Add const qualifier to the argument and automatic variable of type "char *". * desc.c (decode_select): Add const qualifier to automatic variables of type "char *". * ioctlsort.c (struct ioctlent): Add const qualifier to fields of type "char *". (main): Add const qualifier to argv. * process.c (printargv): Add const qualifier to the argument and automatic variable of type "char *". (printargc) Add const qualifier to argument of type "char *". * signal.c (sprintsigmask, parse_sigset_t): Add const qualifier to arguments of type "char *". * strace.c (progname): Add const qualifier. (detach): Add const qualifier to automatic variable of type "char *". * stream.c (struct strbuf): Add const qualifier to the field of type "char *". * syscall.c (struct qual_options): Add const qualifier to fields of type "char *". (qual_syscall, qual_fault, qual_desc, lookup_class): Add const qualifier to arguments of type "char *". (qual_signal): Add const qualifier to the argument of type "char *", avoid modification of constant argument. (qualify): Likewise. * util.c (printflags): Add const qualifier to automatic variable of type "char *". (printnum, printnum_int): Add const qualifier to arguments of type "char *".
This commit is contained in:
parent
cbdd1900a1
commit
30145dda9d
4
count.c
4
count.c
@ -131,7 +131,7 @@ static int (*sortfun)();
|
||||
static struct timeval overhead = { -1, -1 };
|
||||
|
||||
void
|
||||
set_sortby(char *sortby)
|
||||
set_sortby(const char *sortby)
|
||||
{
|
||||
if (strcmp(sortby, "time") == 0)
|
||||
sortfun = time_cmp;
|
||||
@ -161,7 +161,7 @@ call_summary_pers(FILE *outf)
|
||||
int call_cum, error_cum;
|
||||
struct timeval tv_cum, dtv;
|
||||
double percent;
|
||||
char *dashes = "-------------------------";
|
||||
const char *dashes = "-------------------------";
|
||||
char error_str[16];
|
||||
int *sorted_count = calloc(sizeof(int), nsyscalls);
|
||||
|
||||
|
10
defs.h
10
defs.h
@ -424,7 +424,7 @@ struct tcb {
|
||||
|
||||
struct xlat {
|
||||
int val;
|
||||
char *str;
|
||||
const char *str;
|
||||
};
|
||||
|
||||
extern const struct xlat open_mode_flags[];
|
||||
@ -488,9 +488,9 @@ extern void expand_tcbtab(void);
|
||||
|
||||
#define alloctcb(pid) alloc_tcb((pid), 1)
|
||||
|
||||
extern void set_sortby(char *);
|
||||
extern void set_sortby(const char *);
|
||||
extern void set_overhead(int);
|
||||
extern void qualify(char *);
|
||||
extern void qualify(const char *);
|
||||
extern int get_scno(struct tcb *);
|
||||
extern long known_scno(struct tcb *);
|
||||
extern long do_ptrace(int request, struct tcb *tcp, void *addr, void *data);
|
||||
@ -509,8 +509,8 @@ extern int upeek(struct tcb *, long, long *);
|
||||
extern void dumpiov(struct tcb *, int, long);
|
||||
extern void dumpstr(struct tcb *, long, int);
|
||||
extern void printstr(struct tcb *, long, int);
|
||||
extern void printnum(struct tcb *, long, char *);
|
||||
extern void printnum_int(struct tcb *, long, char *);
|
||||
extern void printnum(struct tcb *, long, const char *);
|
||||
extern void printnum_int(struct tcb *, long, const char *);
|
||||
extern void printpath(struct tcb *, long);
|
||||
extern void printpathn(struct tcb *, long, int);
|
||||
extern void printtv_bitness(struct tcb *, long, enum bitness_t, int);
|
||||
|
4
desc.c
4
desc.c
@ -490,7 +490,7 @@ decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
|
||||
& -sizeof(long));
|
||||
fd_set *fds;
|
||||
static char outstr[1024];
|
||||
char *sep;
|
||||
const char *sep;
|
||||
long arg;
|
||||
|
||||
if (entering(tcp)) {
|
||||
@ -529,7 +529,7 @@ decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
|
||||
else
|
||||
{
|
||||
unsigned int cumlen = 0;
|
||||
char *sep = "";
|
||||
const char *sep = "";
|
||||
|
||||
if (syserror(tcp))
|
||||
return 0;
|
||||
|
@ -36,8 +36,8 @@
|
||||
#endif
|
||||
|
||||
struct ioctlent {
|
||||
char *doth;
|
||||
char *symbol;
|
||||
const char *doth;
|
||||
const char *symbol;
|
||||
unsigned long code;
|
||||
};
|
||||
|
||||
@ -56,9 +56,7 @@ const void *b;
|
||||
}
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
|
11
process.c
11
process.c
@ -1630,16 +1630,14 @@ struct tcb *tcp;
|
||||
|
||||
|
||||
static void
|
||||
printargv(tcp, addr)
|
||||
struct tcb *tcp;
|
||||
long addr;
|
||||
printargv(struct tcb *tcp, long addr)
|
||||
{
|
||||
union {
|
||||
unsigned int p32;
|
||||
unsigned long p64;
|
||||
char data[sizeof(long)];
|
||||
} cp;
|
||||
char *sep;
|
||||
const char *sep;
|
||||
int n = 0;
|
||||
|
||||
cp.p64 = 1;
|
||||
@ -1662,10 +1660,7 @@ long addr;
|
||||
}
|
||||
|
||||
static void
|
||||
printargc(fmt, tcp, addr)
|
||||
char *fmt;
|
||||
struct tcb *tcp;
|
||||
long addr;
|
||||
printargc(const char *fmt, struct tcb *tcp, long addr)
|
||||
{
|
||||
int count;
|
||||
char *cp;
|
||||
|
7
signal.c
7
signal.c
@ -315,7 +315,8 @@ sprintsigmask(const char *str, sigset_t *mask, int rt)
|
||||
{
|
||||
int i, nsigs;
|
||||
int maxsigs;
|
||||
char *format, *s;
|
||||
const char *format;
|
||||
char *s;
|
||||
static char outstr[8 * sizeof(sigset_t) * 8];
|
||||
|
||||
strcpy(outstr, str);
|
||||
@ -785,7 +786,7 @@ int verbose;
|
||||
#ifdef LINUX
|
||||
|
||||
static void
|
||||
parse_sigset_t (const char *str, sigset_t *set)
|
||||
parse_sigset_t(const char *str, sigset_t *set)
|
||||
{
|
||||
const char *p;
|
||||
unsigned int digit;
|
||||
@ -832,7 +833,7 @@ int sig;
|
||||
int sfd;
|
||||
char sname[32];
|
||||
char buf[2048];
|
||||
char *s;
|
||||
const char *s;
|
||||
int i;
|
||||
sigset_t ignored, caught;
|
||||
#endif
|
||||
|
4
strace.c
4
strace.c
@ -117,7 +117,7 @@ FILE *outf;
|
||||
static int curcol;
|
||||
struct tcb **tcbtab;
|
||||
unsigned int nprocs, tcbtabsize;
|
||||
char *progname;
|
||||
const char *progname;
|
||||
extern char **environ;
|
||||
|
||||
static int detach(struct tcb *tcp, int sig);
|
||||
@ -531,7 +531,7 @@ startup_child (char **argv)
|
||||
strcpy(pathname, filename);
|
||||
#endif /* USE_DEBUGGING_EXEC */
|
||||
else {
|
||||
char *path;
|
||||
const char *path;
|
||||
int m, n, len;
|
||||
|
||||
for (path = getenv("PATH"); path && *path; path += m) {
|
||||
|
2
stream.c
2
stream.c
@ -57,7 +57,7 @@
|
||||
struct strbuf {
|
||||
int maxlen; /* no. of bytes in buffer */
|
||||
int len; /* no. of bytes returned */
|
||||
char *buf; /* pointer to data */
|
||||
const char *buf; /* pointer to data */
|
||||
};
|
||||
#define MORECTL 1
|
||||
#define MOREDATA 2
|
||||
|
50
syscall.c
50
syscall.c
@ -238,9 +238,9 @@ static int qual_syscall(), qual_signal(), qual_fault(), qual_desc();
|
||||
|
||||
static const struct qual_options {
|
||||
int bitflag;
|
||||
char *option_name;
|
||||
int (*qualify)();
|
||||
char *argument_name;
|
||||
const char *option_name;
|
||||
int (*qualify)(const char *, const struct qual_options *, int);
|
||||
const char *argument_name;
|
||||
} qual_options[] = {
|
||||
{ QUAL_TRACE, "trace", qual_syscall, "system call" },
|
||||
{ QUAL_TRACE, "t", qual_syscall, "system call" },
|
||||
@ -299,10 +299,7 @@ qualify_one(n, opt, not, pers)
|
||||
}
|
||||
|
||||
static int
|
||||
qual_syscall(s, opt, not)
|
||||
char *s;
|
||||
const struct qual_options *opt;
|
||||
int not;
|
||||
qual_syscall(const char *s, const struct qual_options *opt, int not)
|
||||
{
|
||||
int i;
|
||||
int rc = -1;
|
||||
@ -340,10 +337,7 @@ qual_syscall(s, opt, not)
|
||||
}
|
||||
|
||||
static int
|
||||
qual_signal(s, opt, not)
|
||||
char *s;
|
||||
const struct qual_options *opt;
|
||||
int not;
|
||||
qual_signal(const char *s, const struct qual_options *opt, int not)
|
||||
{
|
||||
int i;
|
||||
char buf[32];
|
||||
@ -359,12 +353,10 @@ qual_signal(s, opt, not)
|
||||
return -1;
|
||||
strcpy(buf, s);
|
||||
s = buf;
|
||||
for (i = 0; s[i]; i++)
|
||||
s[i] = toupper((unsigned char)(s[i]));
|
||||
if (strncmp(s, "SIG", 3) == 0)
|
||||
if (strncasecmp(s, "SIG", 3) == 0)
|
||||
s += 3;
|
||||
for (i = 0; i <= NSIG; i++)
|
||||
if (strcmp(s, signame(i) + 3) == 0) {
|
||||
if (strcasecmp(s, signame(i) + 3) == 0) {
|
||||
qualify_one(i, opt, not, -1);
|
||||
return 0;
|
||||
}
|
||||
@ -372,19 +364,13 @@ qual_signal(s, opt, not)
|
||||
}
|
||||
|
||||
static int
|
||||
qual_fault(s, opt, not)
|
||||
char *s;
|
||||
const struct qual_options *opt;
|
||||
int not;
|
||||
qual_fault(const char *s, const struct qual_options *opt, int not)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
qual_desc(s, opt, not)
|
||||
char *s;
|
||||
const struct qual_options *opt;
|
||||
int not;
|
||||
qual_desc(const char *s, const struct qual_options *opt, int not)
|
||||
{
|
||||
if (isdigit((unsigned char)*s)) {
|
||||
int desc = atoi(s);
|
||||
@ -397,8 +383,7 @@ qual_desc(s, opt, not)
|
||||
}
|
||||
|
||||
static int
|
||||
lookup_class(s)
|
||||
char *s;
|
||||
lookup_class(const char *s)
|
||||
{
|
||||
if (strcmp(s, "file") == 0)
|
||||
return TRACE_FILE;
|
||||
@ -416,12 +401,12 @@ lookup_class(s)
|
||||
}
|
||||
|
||||
void
|
||||
qualify(s)
|
||||
char *s;
|
||||
qualify(const char *s)
|
||||
{
|
||||
const struct qual_options *opt;
|
||||
int not;
|
||||
char *p;
|
||||
char *copy;
|
||||
const char *p;
|
||||
int i, n;
|
||||
|
||||
opt = &qual_options[0];
|
||||
@ -451,7 +436,13 @@ char *s;
|
||||
for (i = 0; i < MAX_QUALS; i++) {
|
||||
qualify_one(i, opt, !not, -1);
|
||||
}
|
||||
for (p = strtok(s, ","); p; p = strtok(NULL, ",")) {
|
||||
if (!strchr(s, ','))
|
||||
return;
|
||||
if (!(copy = strdup(s))) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
|
||||
if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
|
||||
for (i = 0; i < nsyscalls0; i++)
|
||||
if (sysent0[i].sys_flags & n)
|
||||
@ -477,6 +468,7 @@ char *s;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
free(copy);
|
||||
return;
|
||||
}
|
||||
|
||||
|
17
util.c
17
util.c
@ -340,13 +340,10 @@ sprintflags(const char *prefix, const struct xlat *xlat, int flags)
|
||||
}
|
||||
|
||||
int
|
||||
printflags(xlat, flags, dflt)
|
||||
const struct xlat *xlat;
|
||||
int flags;
|
||||
const char *dflt;
|
||||
printflags(const struct xlat *xlat, int flags, const char *dflt)
|
||||
{
|
||||
int n;
|
||||
char *sep;
|
||||
const char *sep;
|
||||
|
||||
if (flags == 0 && xlat->val == 0) {
|
||||
tprintf("%s", xlat->str);
|
||||
@ -383,10 +380,7 @@ const char *dflt;
|
||||
}
|
||||
|
||||
void
|
||||
printnum(tcp, addr, fmt)
|
||||
struct tcb *tcp;
|
||||
long addr;
|
||||
char *fmt;
|
||||
printnum(struct tcb *tcp, long addr, const char *fmt)
|
||||
{
|
||||
long num;
|
||||
|
||||
@ -404,10 +398,7 @@ char *fmt;
|
||||
}
|
||||
|
||||
void
|
||||
printnum_int(tcp, addr, fmt)
|
||||
struct tcb *tcp;
|
||||
long addr;
|
||||
char *fmt;
|
||||
printnum_int(struct tcb *tcp, long addr, const char *fmt)
|
||||
{
|
||||
int num;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user