From 5dd8da10c5368f1f7c641252b24203c14ed8d051 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Tue, 30 Sep 2014 20:35:56 +0000 Subject: [PATCH] libc: resolve minix clang warnings Change-Id: If6c42f7346cc1b00b387ae8d3b4f0df3ffb0244f --- minix/include/minix/minlib.h | 3 +++ minix/lib/libc/gen/configfile.c | 2 +- minix/lib/libc/gen/mtab.c | 2 +- minix/lib/libc/gen/servxcheck.c | 8 +++++--- minix/lib/libc/gen/sethostname.c | 4 +++- minix/lib/libc/gen/stderr.c | 1 + minix/lib/libc/sys/fcntl.c | 2 +- minix/lib/libc/sys/gcov_flush_sys.c | 2 +- minix/lib/libc/sys/ioctl.c | 2 +- minix/lib/libc/sys/ptrace.c | 2 +- minix/lib/libc/sys/recvfrom.c | 12 +++++------- minix/lib/libc/sys/sendmsg.c | 1 + minix/lib/libc/sys/sendto.c | 5 +---- minix/lib/libc/sys/setpgid.c | 2 +- minix/lib/libc/sys/setrlimit.c | 4 +--- minix/lib/libc/sys/sizeup.c | 1 + minix/lib/libc/sys/socket.c | 5 +++-- minix/lib/libc/sys/socketpair.c | 1 + minix/lib/libc/sys/sprofile.c | 4 ++-- minix/lib/libc/sys/vectorio.c | 4 +++- 20 files changed, 37 insertions(+), 30 deletions(-) diff --git a/minix/include/minix/minlib.h b/minix/include/minix/minlib.h index 52059eb5a..e958a5b48 100644 --- a/minix/include/minix/minlib.h +++ b/minix/include/minix/minlib.h @@ -15,6 +15,9 @@ void _cpuid(u32_t *eax, u32_t *ebx, u32_t *ecx, u32_t *edx); int load_mtab(char *_prog_name); int get_mtab_entry(char dev[PATH_MAX], char mount_point[PATH_MAX], char type[MNTNAMELEN], char flags[MNTFLAGLEN]); +int servxcheck(unsigned long peer, const char *service, + void (*logf)(int pass, const char *name)); +char *servxfile(const char *file); /* read_tsc() and friends */ void read_tsc(u32_t *hi, u32_t *lo); diff --git a/minix/lib/libc/gen/configfile.c b/minix/lib/libc/gen/configfile.c index 4c6300fea..2907f15ff 100644 --- a/minix/lib/libc/gen/configfile.c +++ b/minix/lib/libc/gen/configfile.c @@ -149,7 +149,7 @@ static void skipwhite(void) } } -static void parse_err(void) +static void __dead parse_err(void) /* Tell user that you can't parse past the current character. */ { char sc[2]; diff --git a/minix/lib/libc/gen/mtab.c b/minix/lib/libc/gen/mtab.c index 88cd1869e..a117f81c2 100644 --- a/minix/lib/libc/gen/mtab.c +++ b/minix/lib/libc/gen/mtab.c @@ -42,7 +42,7 @@ #define BUF_SIZE 512 /* size of the /etc/mtab buffer */ -char *etc_mtab = "/etc/mtab"; /* name of the /etc/mtab file */ +const char *etc_mtab = "/etc/mtab"; /* name of the /etc/mtab file */ static char mtab_in[BUF_SIZE+1]; /* holds /etc/mtab when it is read in */ static char *iptr = mtab_in; /* pointer to next line to feed out. */ diff --git a/minix/lib/libc/gen/servxcheck.c b/minix/lib/libc/gen/servxcheck.c index 47d2caca9..55c61331e 100644 --- a/minix/lib/libc/gen/servxcheck.c +++ b/minix/lib/libc/gen/servxcheck.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include /* Default service access file. */ static const char *path_servacces = _PATH_SERVACCES; @@ -76,12 +78,12 @@ static int netspec(char *word, ipaddr_t *addr, ipaddr_t *mask) if ((slash= strchr(word, '/')) == NULL) slash= S32; *slash= 0; - r= inet_aton(word, addr); + r= inet_aton(word, (struct in_addr *)addr); *slash++= '/'; if (!r) return 0; r= 0; - while ((*slash - '0') < 10u) { + while ((unsigned int)(*slash - '0') < 10u) { r= 10*r + (*slash++ - '0'); if (r > 32) return 0; } @@ -148,7 +150,7 @@ static int get_name(ipaddr_t addr, char *name) } } } - strcpy(name, inet_ntoa(addr)); + strcpy(name, inet_ntoa(*(struct in_addr *)&addr)); return 0; } diff --git a/minix/lib/libc/gen/sethostname.c b/minix/lib/libc/gen/sethostname.c index 5cc3806b9..7d8a64ba6 100644 --- a/minix/lib/libc/gen/sethostname.c +++ b/minix/lib/libc/gen/sethostname.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ int sethostname(const char *buf, size_t len) r = write(fd, buf, len); tmperr = errno; + fsync(fd); close(fd); if (r == -1) { @@ -46,7 +48,7 @@ int sethostname(const char *buf, size_t len) return -1; } - if (r < len) { + if ((size_t)r < len) { unlink(name); errno = ENOSPC; return -1; diff --git a/minix/lib/libc/gen/stderr.c b/minix/lib/libc/gen/stderr.c index fd7f65b4b..63e802fef 100644 --- a/minix/lib/libc/gen/stderr.c +++ b/minix/lib/libc/gen/stderr.c @@ -1,6 +1,7 @@ #include #include #include +#include void std_err(const char *s) { diff --git a/minix/lib/libc/sys/fcntl.c b/minix/lib/libc/sys/fcntl.c index 496dd9a5b..10b99058f 100644 --- a/minix/lib/libc/sys/fcntl.c +++ b/minix/lib/libc/sys/fcntl.c @@ -29,7 +29,7 @@ int fcntl(int fd, int cmd, ...) case F_SETLK: case F_SETLKW: case F_FREESP: - m.m_lc_vfs_fcntl.arg_ptr = va_arg(argp, struct flock *); + m.m_lc_vfs_fcntl.arg_ptr = (vir_bytes)va_arg(argp, struct flock *); break; } diff --git a/minix/lib/libc/sys/gcov_flush_sys.c b/minix/lib/libc/sys/gcov_flush_sys.c index 2382d6b0a..de7d63b3b 100644 --- a/minix/lib/libc/sys/gcov_flush_sys.c +++ b/minix/lib/libc/sys/gcov_flush_sys.c @@ -7,7 +7,7 @@ int gcov_flush_svr(char *buff, int buff_sz, int server_nr) message m; memset(&m, 0, sizeof(m)); - m.m_lc_vfs_gcov.buff_p = buff; + m.m_lc_vfs_gcov.buff_p = (vir_bytes)buff; m.m_lc_vfs_gcov.buff_sz = buff_sz; m.m_lc_vfs_gcov.pid = server_nr; diff --git a/minix/lib/libc/sys/ioctl.c b/minix/lib/libc/sys/ioctl.c index b2211d004..f1eb9cd4e 100644 --- a/minix/lib/libc/sys/ioctl.c +++ b/minix/lib/libc/sys/ioctl.c @@ -71,7 +71,7 @@ int ioctl(int fd, unsigned long request, ...) break; default: /* Keep original as-is */ - addr = data; + addr = (vir_bytes)data; break; } diff --git a/minix/lib/libc/sys/ptrace.c b/minix/lib/libc/sys/ptrace.c index 9dd63a9d3..01ae97483 100644 --- a/minix/lib/libc/sys/ptrace.c +++ b/minix/lib/libc/sys/ptrace.c @@ -12,7 +12,7 @@ int ptrace(int req, pid_t pid, void *addr, int data) memset(&m, 0, sizeof(m)); m.m_lc_pm_ptrace.pid = pid; m.m_lc_pm_ptrace.req = req; - m.m_lc_pm_ptrace.addr = addr; + m.m_lc_pm_ptrace.addr = (vir_bytes)addr; m.m_lc_pm_ptrace.data = data; if (_syscall(PM_PROC_NR, PM_PTRACE, &m) < 0) return(-1); diff --git a/minix/lib/libc/sys/recvfrom.c b/minix/lib/libc/sys/recvfrom.c index 58bba5e46..05a711839 100644 --- a/minix/lib/libc/sys/recvfrom.c +++ b/minix/lib/libc/sys/recvfrom.c @@ -19,7 +19,6 @@ #include #include -#include #define DEBUG 0 @@ -88,15 +87,14 @@ ssize_t recvfrom(int sock, void *__restrict buffer, size_t length, { ip_hdr_t *ip_hdr; - int ihl, rd; - icmp_hdr_t *icmp_hdr; + int rd; struct sockaddr_in sin; rd = read(sock, buffer, length); if(rd < 0) return rd; - assert(rd >= sizeof(*ip_hdr)); + assert((size_t)rd >= sizeof(*ip_hdr)); ip_hdr= buffer; @@ -108,8 +106,8 @@ ssize_t recvfrom(int sock, void *__restrict buffer, size_t length, sin.sin_addr.s_addr= ip_hdr->ih_src; sin.sin_len= sizeof(sin); len= *address_len; - if (len > sizeof(sin)) - len= sizeof(sin); + if ((size_t)len > sizeof(sin)) + len= (int)sizeof(sin); memcpy(address, &sin, len); *address_len= sizeof(sin); } @@ -237,7 +235,7 @@ static ssize_t _udp_recvfrom(int sock, void *__restrict buffer, size_t length, return -1; } - assert(r >= sizeof(*io_hdrp)); + assert((size_t)r >= sizeof(*io_hdrp)); length= r-sizeof(*io_hdrp); io_hdrp= buf; diff --git a/minix/lib/libc/sys/sendmsg.c b/minix/lib/libc/sys/sendmsg.c index c0a342b6a..b13d8a251 100644 --- a/minix/lib/libc/sys/sendmsg.c +++ b/minix/lib/libc/sys/sendmsg.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/minix/lib/libc/sys/sendto.c b/minix/lib/libc/sys/sendto.c index d7d846913..8370773d4 100644 --- a/minix/lib/libc/sys/sendto.c +++ b/minix/lib/libc/sys/sendto.c @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -78,8 +77,6 @@ ssize_t sendto(int sock, const void *message, size_t length, int flags, { ip_hdr_t *ip_hdr; - int ihl; - icmp_hdr_t *icmp_hdr; struct sockaddr_in *sinp; sinp = (struct sockaddr_in *) __UNCONST(dest_addr); @@ -199,7 +196,7 @@ static ssize_t _udp_sendto(int sock, const void *message, size_t length, errno= t_errno; return -1; } - assert(r == buflen); + assert((size_t)r == buflen); free(buf); return length; } diff --git a/minix/lib/libc/sys/setpgid.c b/minix/lib/libc/sys/setpgid.c index b007ba532..b724fa44c 100644 --- a/minix/lib/libc/sys/setpgid.c +++ b/minix/lib/libc/sys/setpgid.c @@ -11,7 +11,7 @@ */ int setpgid(pid_t pid, pid_t pgid) { - pid_t _pid, _pgid, sid, cpid; + pid_t _pid, _pgid, cpid; _pid = pid; _pgid = pgid; diff --git a/minix/lib/libc/sys/setrlimit.c b/minix/lib/libc/sys/setrlimit.c index ffa28edb6..8e94f31b2 100644 --- a/minix/lib/libc/sys/setrlimit.c +++ b/minix/lib/libc/sys/setrlimit.c @@ -9,8 +9,7 @@ /* Simple stub for now. */ int setrlimit(int resource, const struct rlimit *rlp) { - rlim_t limit; - + switch (resource) { case RLIMIT_CPU: @@ -35,4 +34,3 @@ int setrlimit(int resource, const struct rlimit *rlp) return 0; } - diff --git a/minix/lib/libc/sys/sizeup.c b/minix/lib/libc/sys/sizeup.c index 41c0245b1..11df1e96b 100644 --- a/minix/lib/libc/sys/sizeup.c +++ b/minix/lib/libc/sys/sizeup.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/minix/lib/libc/sys/socket.c b/minix/lib/libc/sys/socket.c index f73828a01..6d5350da5 100644 --- a/minix/lib/libc/sys/socket.c +++ b/minix/lib/libc/sys/socket.c @@ -9,9 +9,11 @@ __weak_alias(socket, __socket30) #include #include #include +#include #include #include +#include #include #include #include @@ -148,8 +150,7 @@ static int _udp_socket(int type, int protocol) static int _raw_socket(int type, int protocol) { - int r, fd, t_errno, flags = O_RDWR; - struct sockaddr_in sin; + int fd, flags = O_RDWR; nwio_ipopt_t ipopt; int result; diff --git a/minix/lib/libc/sys/socketpair.c b/minix/lib/libc/sys/socketpair.c index aa07c7399..118e6e40b 100644 --- a/minix/lib/libc/sys/socketpair.c +++ b/minix/lib/libc/sys/socketpair.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/minix/lib/libc/sys/sprofile.c b/minix/lib/libc/sys/sprofile.c index 9f554a49b..0fe27c43f 100644 --- a/minix/lib/libc/sys/sprofile.c +++ b/minix/lib/libc/sys/sprofile.c @@ -23,8 +23,8 @@ int sprofile(int action, m.m_lc_pm_sprof.mem_size = size; m.m_lc_pm_sprof.freq = freq; m.m_lc_pm_sprof.intr_type = type; - m.m_lc_pm_sprof.ctl_ptr = ctl_ptr; - m.m_lc_pm_sprof.mem_ptr = mem_ptr; + m.m_lc_pm_sprof.ctl_ptr = (vir_bytes)ctl_ptr; + m.m_lc_pm_sprof.mem_ptr = (vir_bytes)mem_ptr; return _syscall(PM_PROC_NR, PM_SPROF, &m); } diff --git a/minix/lib/libc/sys/vectorio.c b/minix/lib/libc/sys/vectorio.c index fa14a37b8..6639ea98a 100644 --- a/minix/lib/libc/sys/vectorio.c +++ b/minix/lib/libc/sys/vectorio.c @@ -39,7 +39,9 @@ static ssize_t vectorio_buffer(int fildes, const struct iovec *iov, while (copied < r) { assert(iovidx < iovcnt); - len = MIN(r - copied, iov[iovidx].iov_len); + len = iov[iovidx].iov_len; + if (len > r - copied) + len = r - copied; memcpy(iov[iovidx++].iov_base, buffer + copied, len); copied += len; } -- 2.44.0