From: David van Moolenbroek Date: Thu, 17 Dec 2015 13:50:28 +0000 (+0000) Subject: trace(1): resolve all level-5 LLVM warnings X-Git-Url: http://zhaoyanbai.com/repos/Bv9ARM.ch07.html?a=commitdiff_plain;h=refs%2Fchanges%2F67%2F3267%2F3;p=minix.git trace(1): resolve all level-5 LLVM warnings Change-Id: If5ffe97eb0b15387b1ab674657879e13f58fb27e --- diff --git a/minix/usr.bin/trace/Makefile b/minix/usr.bin/trace/Makefile index 26580624e..e875453c1 100644 --- a/minix/usr.bin/trace/Makefile +++ b/minix/usr.bin/trace/Makefile @@ -10,6 +10,8 @@ SRCS+= block.o char.o net.o svrctl.o CPPFLAGS+= -D_MINIX_SYSTEM=1 -I${.CURDIR} -I${NETBSDSRCDIR}/minix +COPTS.format.c+= -Wno-format-nonliteral + error.c: error.awk ${NETBSDSRCDIR}/sys/sys/errno.h ${TOOL_AWK} -f ${.ALLSRC} > ${.TARGET} @@ -18,4 +20,6 @@ signal.c: signal.awk ${NETBSDSRCDIR}/sys/sys/signal.h CLEANFILES+= error.c signal.c +WARNS?= 5 + .include diff --git a/minix/usr.bin/trace/call.c b/minix/usr.bin/trace/call.c index b4de797c5..4f06920e9 100644 --- a/minix/usr.bin/trace/call.c +++ b/minix/usr.bin/trace/call.c @@ -21,17 +21,17 @@ static const struct calls *call_table[] = { static const struct call_handler * find_handler(endpoint_t endpt, int call_nr) { - int i, index; + unsigned int i, index; for (i = 0; i < COUNT(call_table); i++) { if (call_table[i]->endpt != ANY && call_table[i]->endpt != endpt) continue; - if (call_nr < call_table[i]->base) + if ((unsigned int)call_nr < call_table[i]->base) continue; - index = call_nr - call_table[i]->base; + index = (unsigned int)call_nr - call_table[i]->base; if (index >= call_table[i]->count) continue; diff --git a/minix/usr.bin/trace/error.awk b/minix/usr.bin/trace/error.awk index 747616230..f6a404615 100644 --- a/minix/usr.bin/trace/error.awk +++ b/minix/usr.bin/trace/error.awk @@ -19,7 +19,7 @@ BEGIN { END { printf("};\n\n"); printf("const char *\nget_error_name(int err)\n{\n\n"); - printf("\tif (err >= 0 && err < sizeof(errors) / sizeof(errors[0]) &&\n"); + printf("\tif (err >= 0 && (unsigned int)err < __arraycount(errors) &&\n"); printf("\t errors[err] != NULL)\n"); printf("\t\treturn errors[err];\n"); printf("\telse\n"); diff --git a/minix/usr.bin/trace/format.c b/minix/usr.bin/trace/format.c index 10a6b3eb2..5e72ad6dc 100644 --- a/minix/usr.bin/trace/format.c +++ b/minix/usr.bin/trace/format.c @@ -249,7 +249,8 @@ put_buf(struct trace_proc * proc, const char * name, int flags, vir_bytes addr, { const char *escaped; size_t len, off, max, chunk; - int i, cutoff; + unsigned int i; + int cutoff; char *p; if ((flags & PF_FAILED) || valuesonly || addr == 0 || size < 0) { diff --git a/minix/usr.bin/trace/ioctl.c b/minix/usr.bin/trace/ioctl.c index 4c4b49834..70f2479e4 100644 --- a/minix/usr.bin/trace/ioctl.c +++ b/minix/usr.bin/trace/ioctl.c @@ -26,8 +26,8 @@ put_ioctl_req(struct trace_proc * proc, const char * name, unsigned long req, { const char *text; size_t size; - unsigned int group, cmd; - int i, r, w, big; + unsigned int i, group, cmd; + int r, w, big; proc->ioctl_index = -1; @@ -124,7 +124,7 @@ put_ioctl_arg_out(struct trace_proc * proc, const char * name, } assert(proc->ioctl_index >= 0); - assert(proc->ioctl_index < COUNT(ioctl_table)); + assert((unsigned int)proc->ioctl_index < COUNT(ioctl_table)); assert(ioctl_table[proc->ioctl_index].is_svrctl == is_svrctl); proc->ioctl_flags = @@ -193,7 +193,7 @@ put_ioctl_arg_in(struct trace_proc * proc, const char * name, int failed, } assert(proc->ioctl_index >= 0); - assert(proc->ioctl_index < COUNT(ioctl_table)); + assert((unsigned int)proc->ioctl_index < COUNT(ioctl_table)); assert(ioctl_table[proc->ioctl_index].is_svrctl == is_svrctl); assert(proc->ioctl_flags != 0); diff --git a/minix/usr.bin/trace/ioctl/net.c b/minix/usr.bin/trace/ioctl/net.c index 3a4f42847..90be38735 100644 --- a/minix/usr.bin/trace/ioctl/net.c +++ b/minix/usr.bin/trace/ioctl/net.c @@ -290,7 +290,7 @@ put_msg_control(struct trace_proc * proc, struct msg_control * ptr) struct msghdr msg; struct cmsghdr *cmsg; size_t len; - int i; + unsigned int i; if (ptr->msg_controllen > sizeof(ptr->msg_control)) { put_field(proc, NULL, ".."); diff --git a/minix/usr.bin/trace/kernel.c b/minix/usr.bin/trace/kernel.c index bb84f2b7a..16c3ab907 100644 --- a/minix/usr.bin/trace/kernel.c +++ b/minix/usr.bin/trace/kernel.c @@ -253,12 +253,12 @@ kernel_get_nextframe(pid_t pid, reg_t fp, reg_t * next_pc, reg_t * next_fp) * processes being attached to, and not for exec calls using a relative path. */ void -kernel_put_stacktrace(struct trace_proc * proc) +kernel_put_stacktrace(struct trace_proc * procp) { unsigned int count, max; reg_t pc, sp, fp, low, high; - if (kernel_get_context(proc->pid, &pc, &sp, &fp) < 0) + if (kernel_get_context(procp->pid, &pc, &sp, &fp) < 0) return; /* @@ -275,15 +275,15 @@ kernel_put_stacktrace(struct trace_proc * proc) * the lines straight into tools such as addr2line. */ put_newline(); - put_fmt(proc, " 0x%x", pc); + put_fmt(procp, " 0x%x", pc); low = high = fp; for (count = 1; count < max && fp != 0; count++) { - if (kernel_get_nextframe(proc->pid, fp, &pc, &fp) < 0) + if (kernel_get_nextframe(procp->pid, fp, &pc, &fp) < 0) break; - put_fmt(proc, " 0x%x", pc); + put_fmt(procp, " 0x%x", pc); /* * Stop if we see a frame pointer that falls within the range @@ -299,6 +299,6 @@ kernel_put_stacktrace(struct trace_proc * proc) } if (fp != 0) - put_text(proc, " .."); + put_text(procp, " .."); put_newline(); } diff --git a/minix/usr.bin/trace/service/mib.c b/minix/usr.bin/trace/service/mib.c index d98a0f619..a56df1676 100644 --- a/minix/usr.bin/trace/service/mib.c +++ b/minix/usr.bin/trace/service/mib.c @@ -24,9 +24,9 @@ put_kern_clockrate(struct trace_proc * proc, const char * name, int type __unused, const void * ptr, vir_bytes addr __unused, size_t size __unused) { - struct clockinfo *ci; + const struct clockinfo *ci; - ci = (struct clockinfo *)ptr; + ci = (const struct clockinfo *)ptr; put_value(proc, "hz", "%d", ci->hz); put_value(proc, "tick", "%d", ci->tick); @@ -48,7 +48,7 @@ put_kern_proc2(struct trace_proc * proc, const char * name, int type, { const int *mib; const char *text; - int i; + unsigned int i; if (type == ST_NAME) { mib = (const int *)ptr; @@ -114,7 +114,8 @@ put_kern_proc_args(struct trace_proc * proc, const char * name, int type, { const int *mib; const char *text; - int i, v; + unsigned int i; + int v; if (type == ST_NAME) { mib = (const int *)ptr; @@ -164,7 +165,7 @@ static int put_kern_cp_time(struct trace_proc * proc, const char * name __unused, int type, const void * ptr, vir_bytes addr __unused, size_t size) { - uint64_t *p; + const uint64_t *p; unsigned int i; const int *mib; @@ -176,7 +177,7 @@ put_kern_cp_time(struct trace_proc * proc, const char * name __unused, return 0; } - p = (uint64_t *)ptr; + p = (const uint64_t *)ptr; /* TODO: support for multi-CPU results */ for (i = 0; i < CPUSTATES; i++) @@ -194,7 +195,7 @@ put_kern_consdev(struct trace_proc * proc, const char * name, size_t size __unused) { - put_dev(proc, NULL, *(dev_t *)ptr); + put_dev(proc, NULL, *(const dev_t *)ptr); return TRUE; } @@ -243,7 +244,7 @@ put_kern_sysvipc_info(struct trace_proc * proc, const char * name, { const int *mib; const char *text; - int i; + unsigned int i; /* * TODO: print the obtained structure(s). For now we are just @@ -302,10 +303,10 @@ put_vm_loadavg(struct trace_proc * proc, const char * name __unused, int type __unused, const void * ptr, vir_bytes addr __unused, size_t size __unused) { - struct loadavg *loadavg; + const struct loadavg *loadavg; unsigned int i; - loadavg = (struct loadavg *)ptr; + loadavg = (const struct loadavg *)ptr; put_open(proc, "ldavg", 0, "{", ", "); @@ -374,7 +375,7 @@ static const struct flags sysctl_flags[] = { static void put_sysctl_imm(struct trace_proc * proc, struct sysctlnode * scn, int use_name) { - char *name; + const char *name; name = NULL; @@ -569,9 +570,6 @@ put_sysctl_generic(struct trace_proc * proc, const char * name, int type, { struct sysctlnode scn; void *ptr; - int i; - bool b; - u_quad_t q; size_t len; switch (SYSCTL_TYPE(proc->sctl_flags)) { @@ -837,7 +835,6 @@ put_sysctl_name(struct trace_proc * proc, const char * name, int flags, vir_bytes addr, unsigned int namelen) { const struct sysctl_tab *sct = NULL; - const char *namestr; int r, all, namebuf[CTL_MAXNAME]; unsigned int n; diff --git a/minix/usr.bin/trace/service/vfs.c b/minix/usr.bin/trace/service/vfs.c index 8052ef072..c928f2e26 100644 --- a/minix/usr.bin/trace/service/vfs.c +++ b/minix/usr.bin/trace/service/vfs.c @@ -596,7 +596,6 @@ put_struct_flock(struct trace_proc * proc, const char * name, int flags, static int vfs_fcntl_out(struct trace_proc * proc, const message * m_out) { - int full; put_fd(proc, "fd", m_out->m_lc_vfs_fcntl.fd); put_fcntl_cmd(proc, "cmd", m_out->m_lc_vfs_fcntl.cmd); @@ -793,9 +792,9 @@ put_dirent_array(struct trace_proc * proc, const char * name, int flags, count = 0; for (off = 0; off < size; off += chunk) { chunk = size - off; - if (chunk > sizeof(dirent)) - chunk = sizeof(dirent); - if (chunk < _DIRENT_MINSIZE(&dirent)) + if ((size_t)chunk > sizeof(dirent)) + chunk = (ssize_t)sizeof(dirent); + if ((size_t)chunk < _DIRENT_MINSIZE(&dirent)) break; if (mem_get_data(proc->pid, addr + off, &dirent, chunk) < 0) { diff --git a/minix/usr.bin/trace/signal.awk b/minix/usr.bin/trace/signal.awk index 84c54b80c..985f8d7e0 100644 --- a/minix/usr.bin/trace/signal.awk +++ b/minix/usr.bin/trace/signal.awk @@ -23,7 +23,7 @@ BEGIN { END { printf("};\n\n"); printf("const char *\nget_signal_name(int sig)\n{\n\n"); - printf("\tif (sig >= 0 && sig < sizeof(signals) / sizeof(signals[0]) &&\n"); + printf("\tif (sig >= 0 && (unsigned int)sig < __arraycount(signals) &&\n"); printf("\t signals[sig] != NULL)\n"); printf("\t\treturn signals[sig];\n"); printf("\telse\n"); diff --git a/minix/usr.bin/trace/type.h b/minix/usr.bin/trace/type.h index e126a8d74..750c030b6 100644 --- a/minix/usr.bin/trace/type.h +++ b/minix/usr.bin/trace/type.h @@ -1,5 +1,5 @@ -#define COUNT(s) (sizeof(s) / sizeof(s[0])) +#define COUNT(s) (__arraycount(s)) struct call_handler { const char *name;