]> granicus.if.org Git - strace/commitdiff
Fix const-correctness issues uncovered by gcc -Wwrite-strings
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 6 Sep 2010 22:08:24 +0000 (22:08 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 7 Sep 2010 00:59:18 +0000 (00:59 +0000)
* 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 *".

count.c
defs.h
desc.c
ioctlsort.c
process.c
signal.c
strace.c
stream.c
syscall.c
util.c

diff --git a/count.c b/count.c
index d0ea016947814fc763b39ccc2a6e5a0d364c3cf8..92f7849ba403f82418285375d89c8695d4ed2574 100644 (file)
--- a/count.c
+++ b/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);
 
diff --git a/defs.h b/defs.h
index 4b9c29e4322db605784823e3f6ef845cf45b9d55..fc7e362add39d94444b19549b06058736cb38a0d 100644 (file)
--- a/defs.h
+++ b/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);
diff --git a/desc.c b/desc.c
index 9571e494078a2bcdce6ea650a218505c32df0318..2b9f30a44b82a27c385424a5bbeab069091cf338 100644 (file)
--- a/desc.c
+++ b/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;
index 1009d751c771111e6f81a59ebe2047ac652947d3..7881a918c4e2685c543884d93afd50702ee7f077 100644 (file)
@@ -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;
 
index 8af960a0ab5f05e533b555d814e178defb8160e2..cb927f26232f3e32637c1ebd937b9bf5fc0d3438 100644 (file)
--- a/process.c
+++ b/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;
index 1ccad402b096ef82c2f4822e32e01249cb666d74..eb658d7923ef2a97c1af9b1f8c01a71635863fad 100644 (file)
--- a/signal.c
+++ b/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
index c1d65398498a15741cd91f088e60ee8a0677170f..3cb3758c04c2884ddb0dbb1666ae0a5e36e1e776 100644 (file)
--- a/strace.c
+++ b/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) {
index 41fd82342a6367956f2a77fee707735afb21d66f..e5868c98499b23842273b0539db1be4daac73ea3 100644 (file)
--- a/stream.c
+++ b/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
index 38f628b682575998397f0fa434888c022122c7e7..f3f6d0e55689ec2e202a4140e49e6276174f0eee 100644 (file)
--- a/syscall.c
+++ b/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;
 }
 
diff --git a/util.c b/util.c
index 07cbfdeda40b308843318581a9beea61af7c2ee6..c28edf3be538de233a2c21b5c2268f7bb09987fa 100644 (file)
--- a/util.c
+++ b/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;