From: David van Moolenbroek Date: Fri, 5 Aug 2016 12:28:41 +0000 (+0200) Subject: Resolve a number of GCC-generated warnings X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=3083d603ba9dea68befc9da05a714884e10ec7e8;p=minix.git Resolve a number of GCC-generated warnings The warnings in test47 seem to be a symptom of a larger problem, i.e., not an issue with the test set code but rather with the GCC configuration. Hopefully the switch to LLVM will resolve those. Change-Id: Ic9fa3b8bc9b728947c993f2e1ed49d9a3b731344 --- diff --git a/minix/commands/partition/partition.c b/minix/commands/partition/partition.c index be462376f..103e1f906 100644 --- a/minix/commands/partition/partition.c +++ b/minix/commands/partition/partition.c @@ -376,7 +376,7 @@ void distribute(void) if (base > pe->lowsec) { fprintf(stderr, "%s: fixed partition %u is preceded by too big partitions/holes\n", - arg0, ((pe - table) - 1) / 2); + arg0, ((unsigned int)(pe - table) - 1) / 2); exit(1); } exp= nil; /* XXX - Extend before? */ diff --git a/minix/tests/test48.c b/minix/tests/test48.c index ef8d55733..5cb239176 100644 --- a/minix/tests/test48.c +++ b/minix/tests/test48.c @@ -495,7 +495,7 @@ static int buflens[] = { 0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 255 }; static void test_getnameinfo_all(void) { int flag_NUMERICHOST, flag_NAMEREQD, flag_NUMERICSERV, flag_DGRAM; - int exp_results, flagcount, flags, i, j, k, l, socktypemismatch; + int exp_results, flagcount, flags, i, j, k, l; const char *nodename, *servname; /* set ports servent structs */ @@ -555,10 +555,6 @@ static void test_getnameinfo_all(void) if (buflens[k] > 0 && buflens[k] <= strlen(nodename)) exp_results |= (1 << EAI_OVERFLOW) | (1 << EAI_MEMORY); - socktypemismatch = - (flag_DGRAM && ports[j].socktype == SOCK_STREAM) || - (!flag_DGRAM && ports[j].socktype == SOCK_DGRAM); - struct servent *se = flag_DGRAM ? ports[j].se_udp : ports[j].se_tcp; servname = (flag_NUMERICSERV) ? diff --git a/minix/tests/test53.c b/minix/tests/test53.c index 2a1b8a6f1..672d20931 100644 --- a/minix/tests/test53.c +++ b/minix/tests/test53.c @@ -166,6 +166,13 @@ static void testmul(void) } } +static void do_not_optimize_away(volatile u64_t * ptr) +{ + + /* TODO: does this actually do the job? */ + *ptr ^= 1; +} + static void testdiv0(void) { int funcidx; @@ -187,6 +194,8 @@ static void testdiv0(void) default: assert(0); ERR; break; } + do_not_optimize_away((volatile u64_t *)&res); + /* if we reach this point there was no signal and an * error has been recorded */ diff --git a/minix/tests/test67.c b/minix/tests/test67.c index 68033a807..8379fdaed 100644 --- a/minix/tests/test67.c +++ b/minix/tests/test67.c @@ -171,7 +171,7 @@ start_socket_server(int port) #if !defined(__minix) int yes = 1; #endif - int fd_sock, fd_new, r; + int fd_sock, fd_new; struct sockaddr_in my_addr; struct sockaddr_in other_addr; socklen_t other_size; @@ -220,7 +220,7 @@ start_socket_server(int port) e(5); } - r = read(fd_new, buf, sizeof(buf)); + (void)read(fd_new, buf, sizeof(buf)); exit(0); } diff --git a/minix/tests/test74.c b/minix/tests/test74.c index 8478e037b..8a3ab0a59 100644 --- a/minix/tests/test74.c +++ b/minix/tests/test74.c @@ -201,16 +201,14 @@ static void do_readlink2(void *buf, int fd, int writable) static void do_symlink1(void *buf, int fd, int writable) { - int r; /* the system call just has to fail gracefully */ - r = symlink(buf, NODENAME); + (void)symlink(buf, NODENAME); } static void do_symlink2(void *buf, int fd, int writable) { - int r; /* the system call just has to fail gracefully */ - r = symlink(NODENAME, buf); + (void)symlink(NODENAME, buf); } static void do_open(void *buf, int fd, int writable) @@ -223,26 +221,23 @@ static void do_open(void *buf, int fd, int writable) static void do_select1(void *buf, int fd, int writable) { - int r; struct timeval timeout = { 0, 200000 }; /* 0.2 sec */ /* the system call just has to fail gracefully */ - r = select(1, buf, NULL, NULL, &timeout); + (void)select(1, buf, NULL, NULL, &timeout); } static void do_select2(void *buf, int fd, int writable) { - int r; struct timeval timeout = { 0, 200000 }; /* 1 sec */ /* the system call just has to fail gracefully */ - r = select(1, NULL, buf, NULL, &timeout); + (void)select(1, NULL, buf, NULL, &timeout); } static void do_select3(void *buf, int fd, int writable) { - int r; struct timeval timeout = { 0, 200000 }; /* 1 sec */ /* the system call just has to fail gracefully */ - r = select(1, NULL, NULL, buf, &timeout); + (void)select(1, NULL, NULL, buf, &timeout); } static void fillfile(int fd, int size) diff --git a/minix/tests/test87.c b/minix/tests/test87.c index 99c621d0e..02e043f02 100644 --- a/minix/tests/test87.c +++ b/minix/tests/test87.c @@ -150,7 +150,7 @@ test87a(void) pid_t pid; u_quad_t q; bool b, b2; - int i, va[2], lastva, mib[CTL_MAXNAME + 1]; + int i, va[2], lastva = -1 /*gcc*/, mib[CTL_MAXNAME + 1]; subtest = 0; @@ -1668,7 +1668,7 @@ test87c(void) if (errno != EINVAL) e(0); memcpy(&scn, &tmpscn, sizeof(scn)); - scn.sysctl_size = SSIZE_MAX + 1; + scn.sysctl_size = (size_t)SSIZE_MAX + 1; if (sysctl(mib, 3, NULL, NULL, &scn, sizeof(scn)) != -1) e(0); if (errno != EINVAL) e(0); @@ -1806,7 +1806,7 @@ test87c(void) if (errno != EINVAL) e(0); memcpy(&scn, &tmpscn, sizeof(scn)); - scn.sysctl_size = SSIZE_MAX + 1; + scn.sysctl_size = (size_t)SSIZE_MAX + 1; if (sysctl(mib, 3, NULL, NULL, &scn, sizeof(scn)) != -1) e(0); if (errno != EINVAL) e(0); @@ -2950,14 +2950,17 @@ test87f(void) * contents match expectations, or -1 if they do not. */ static int -test_buf(unsigned char * buf, unsigned char c, size_t size, int set) +test_buf(char * buf, unsigned char c, size_t size, int set) { + unsigned char *ptr; int step; + ptr = (unsigned char *)buf; + for (step = 1; size > 0; size--) { if (set) - *buf++ = c; - else if (*buf++ != c) + *ptr++ = c; + else if (*ptr++ != c) return -1; c += step; diff --git a/minix/tests/test88.c b/minix/tests/test88.c index 753bac2d3..056ea46e4 100644 --- a/minix/tests/test88.c +++ b/minix/tests/test88.c @@ -68,7 +68,7 @@ static void *bad_ptr; * Drop user and group privileges in the child process if requested. */ static void -spawn(struct link * link, void (* proc)(), int drop) +spawn(struct link * link, void (* proc)(struct link *), int drop) { struct passwd *pw; struct group *gr; @@ -1592,7 +1592,7 @@ test88c_perm1(struct link * parent) */ memset(val, 0, sizeof(val)); - for (i = 0; i < 4; i++) { + for (i = 0; i < 3; i++) { switch (i) { case 0: cmd = GETALL; @@ -1609,6 +1609,8 @@ test88c_perm1(struct link * parent) ptr = &semds; bit = 4; break; + default: + abort(); } r = semctl(id[0], 0, cmd, ptr); diff --git a/minix/tests/test89.c b/minix/tests/test89.c index 00fef6a85..516f86f2b 100644 --- a/minix/tests/test89.c +++ b/minix/tests/test89.c @@ -298,6 +298,9 @@ test_one_uid(int setnum, int sub) sub89b(setnum); return; + + default: + abort(); } if (res != 0 && (res != -1 || errno != EPERM)) e(setnum); @@ -635,6 +638,9 @@ test_one_gid(int setnum, int sub) sub89d(setnum); return; + + default: + abort(); } if (res != 0 && (res != -1 || errno != EPERM)) e(setnum);