Turn on warnings when building libap.

For ape, we never enabled warnings in cflags.
Turning it on brings up a lot of warnings. Most are noise,
but a few caught unused variables and trunctaions of pointers.
to smaller integers (int, long).

A few warnings remain.
This commit is contained in:
Ori Bernstein 2019-06-21 10:00:58 -07:00
parent 0af7d1fe35
commit d4bc9052be
49 changed files with 168 additions and 126 deletions

View file

@ -5,7 +5,7 @@ APEBIN=/$objtype/bin/ape # where installed ape binaries go
APELIB=/rc/bin/ape # where helper programs go
CC=pcc # compiler (must be ansi)
LD=pcc # loader
CFLAGS= # global defaults
CFLAGS=-Fw # global defaults
FAMILY=plan9
AR=ar # manipulating libraries
RANLIB=echo # for updating libraries

View file

@ -16,5 +16,5 @@ OFILES=\
</sys/src/cmd/mksyslib
CFLAGS=-c -D_POSIX_SOURCE -D_PLAN9_SOURCE
CFLAGS=$CFLAGS -c -D_POSIX_SOURCE -D_PLAN9_SOURCE

View file

@ -6,7 +6,7 @@ char *
getenv(const char *name)
{
char **p = environ;
char *v, *s1, *s2;
char *s1, *s2;
while (*p != NULL){
for(s1 = (char *)name, s2 = *p++; *s1 == *s2; s1++, s2++)

View file

@ -5,7 +5,7 @@ memchr(const void *ap, int c, size_t n)
{
unsigned char *sp;
sp = ap;
sp = (unsigned char*)ap;
c &= 0xFF;
while(n > 0) {
if(*sp++ == c)

View file

@ -6,8 +6,8 @@ memcmp(const void *a1, const void *a2, size_t n)
char *s1, *s2;
unsigned c1, c2;
s1 = a1;
s2 = a2;
s1 = (char*)a1;
s2 = (char*)a2;
while(n > 0) {
c1 = *s1++;
c2 = *s2++;

View file

@ -11,7 +11,7 @@ memmove(void *a1, const void *a2, size_t n)
if(a1 > a2)
goto back;
s1 = a1;
s2 = a2;
s2 = (char*)a2;
while(n > 0) {
*s1++ = *s2++;
n--;

View file

@ -63,4 +63,4 @@ OFILES= `{rc ./reduce $O $objtype $ALLOFILES}
</sys/src/cmd/mksyslib
CFLAGS=-c -D_POSIX_SOURCE
CFLAGS=$CFLAGS -c -D_POSIX_SOURCE

View file

@ -9,16 +9,16 @@ putenv(const char *str)
int n;
for(n = 0; s2 = environ[n]; n++)
for(s1 = str; *s1 == *s2; s1++, s2++)
for(s1 = (char *)str; *s1 == *s2; s1++, s2++)
if(*s1 == '\0' || *s1 == '='){
environ[n] = str;
environ[n] = (char*)str;
return 0;
}
e = realloc(environ, (n+1) * sizeof(char*));
if(e == 0)
return -1;
environ = e;
e[n++] = str;
e[n++] = (char*)str;
e[n] = 0;
return 0;
}

View file

@ -27,8 +27,6 @@ srand(unsigned int seed)
rng_tap = rng_vec;
rng_feed = rng_vec+LEN-TAP;
seed = seed%M;
if(seed < 0)
seed += M;
if(seed == 0)
seed = 89482311;
x = seed;

View file

@ -13,7 +13,7 @@ strcspn(const char *s, const char *b)
if(*b++ == 0)
break;
}
os = s;
os = (char*)s;
while(map[*(unsigned char*)s++] == 0)
;
return s - os - 1;

View file

@ -15,6 +15,6 @@ strpbrk(const char *s, const char *b)
while(map[*s++] == 0)
;
if(*--s)
return s;
return (char*)s;
return 0;
}

View file

@ -9,6 +9,6 @@ strrchr(const char *s, int c)
return strchr(s, 0);
r = 0;
while(s = strchr(s, c))
r = s++;
r = (char*)s++;
return r;
}

View file

@ -10,7 +10,7 @@ strspn(const char *s, const char *b)
memset(map, 0, N);
while(*b)
map[*(unsigned char *)b++] = 1;
os = s;
os = (char*)s;
while(map[*(unsigned char *)s++])
;
return s - os - 1;

View file

@ -2,19 +2,19 @@
/* Return pointer to first occurrence of s2 in s1, NULL if none */
char
*strstr(const char *s1, const char *s2)
char*
strstr(const char *s1, const char *s2)
{
char *p, *pa, *pb;
int c0, c;
c0 = *s2;
if(c0 == 0)
return s1;
return (char *)s1;
s2++;
for(p=strchr(s1, c0); p; p=strchr(p+1, c0)) {
pa = p;
for(pb=s2;; pb++) {
for(pb=(char*)s2;; pb++) {
c = *pb;
if(c == 0)
return p;

View file

@ -25,4 +25,4 @@ OFILES=\
</sys/src/cmd/mksyslib
CFLAGS=-c -D_POSIX_SOURCE
CFLAGS=$CFLAGS -c -D_POSIX_SOURCE

View file

@ -2,6 +2,7 @@
#define _LOCK_EXTENSION
#include "lib.h"
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
@ -57,7 +58,7 @@ _startbuf(int fd)
if(mux == 0){
_RFORK(RFREND);
mux = (Muxseg*)_SEGATTACH(0, "shared", 0, sizeof(Muxseg));
if((long)mux == -1){
if(mux == (void*)-1){
_syserrno();
return -1;
}
@ -124,7 +125,7 @@ Found:
while((v = _RENDEZVOUS(&b->copypid, 0)) == (void*)~0)
;
_muxsid = (int)v;
_muxsid = (uintptr_t)v;
/* leave fd open in parent so system doesn't reuse it */
return 0;
@ -182,6 +183,7 @@ _copyproc(int fd, Muxbuf *b)
* happened, or it might mean eof; try several times to
* disambiguate (posix read() discards 0-length messages)
*/
n = 0;
nzeros = 0;
do {
if(b->fd != fd)
@ -395,7 +397,7 @@ select(int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *timeo
}
mux->selwait = 1;
unlock(&mux->lock);
fd = (int)_RENDEZVOUS(&mux->selwait, 0);
fd = (int)(uintptr_t)_RENDEZVOUS(&mux->selwait, 0);
if(fd >= 0 && fd < nfds) {
b = _fdinfo[fd].buf;
if(b == 0 || b->fd != fd) {
@ -504,7 +506,7 @@ _detachbuf(void)
}
static int
copynotehandler(void *u, char *msg)
copynotehandler(void *, char *)
{
if(_finishing)
_finish(0, 0);

View file

@ -40,6 +40,8 @@ _envsetup(void)
char **pp;
Dir *d9, *d9a;
ps = 0;
psize = 0;
nohandle = 0;
fdinited = 0;
cnt = 0;

View file

@ -59,6 +59,7 @@ _getpw(int *pnum, char **pname, char **plist)
return 0;
au[n] = 0;
}
mem = nil;
matchnum = (*pname == NULL);
matched = 0;
/* try using memo */
@ -68,9 +69,8 @@ _getpw(int *pnum, char **pname, char **plist)
matched = (mem->num == *pnum);
else
matched = (strcmp(mem->name, *pname) == 0);
if(matched) {
if(matched)
break;
}
}
if(!matched)
for(f1 = au, eline = au; !matched && *eline; f1 = eline+1){

View file

@ -1,5 +1,6 @@
#include "lib.h"
#include <errno.h>
#include <stdint.h>
#include "sys9.h"
char end[];
@ -11,7 +12,7 @@ brk(char *p)
{
unsigned long n;
n = (unsigned long)p;
n = (uintptr_t)p;
n += 3;
n &= ~3;
if(_BRK_((void*)n) < 0){

View file

@ -1,25 +1,25 @@
#include <termios.h>
speed_t
cfgetospeed(const struct termios *p)
cfgetospeed(const struct termios *)
{
return B0;
}
int
cfsetospeed(struct termios *p, speed_t s)
cfsetospeed(struct termios *, speed_t)
{
return 0;
}
speed_t
cfgetispeed(const struct termios *p)
cfgetispeed(const struct termios *)
{
return B0;
}
int
cfsetispeed(struct termios *p, speed_t s)
cfsetispeed(struct termios *, speed_t)
{
return 0;
}

View file

@ -1,7 +1,7 @@
#include <unistd.h>
int
execle(const char *name, const char *arg0, const char *aore, ...)
execle(const char *name, const char *arg0, const char *, ...)
{
char *p;

View file

@ -85,7 +85,7 @@ execve(const char *name, const char *argv[], const char *envp[])
_CLOSE(f);
}
if(envp){
for(e = envp; (ss = *e); e++) {
for(e = (char**)envp; (ss = *e); e++) {
se = strchr(ss, '=');
if(!se || ss==se)
continue; /* what is name? value? */

View file

@ -3,7 +3,7 @@
#include <errno.h>
int
fsync(int fd)
fsync(int)
{
errno = EINVAL;
return -1;

View file

@ -13,7 +13,7 @@ getgrnam(const char *name)
char *nam, *mem;
num = 0;
nam = name;
nam = (char *)name;
mem = 0;
if(_getpw(&num, &nam, &mem)){
holdgroup.gr_name = nam;

View file

@ -3,7 +3,7 @@
#include <errno.h>
int
getgroups(int gidsize, gid_t grouplist[])
getgroups(int, gid_t*)
{
errno = EINVAL;
return -1;

View file

@ -14,7 +14,7 @@ getpwnam(const char *name)
char *nam, *mem;
num = 0;
nam = name;
nam = (char*)name;
mem = 0;
if(_getpw(&num, &nam, &mem)){
holdpw.pw_name = nam;

View file

@ -5,7 +5,7 @@
* BUG: LINK_MAX==1 isn't really allowed
*/
int
link(const char *name1, const char *name2)
link(const char *, const char *)
{
errno = EMLINK;
return -1;

View file

@ -107,6 +107,6 @@ UPDATE=\
</sys/src/cmd/mksyslib
CFLAGS=-c -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_BSD_EXTENSION
CFLAGS=$CFLAGS -c -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_BSD_EXTENSION
$OFILES: lib.h

View file

@ -26,7 +26,7 @@ opendir(const char *filename)
s[n++] = '/';
s[n] = 0;
} else
s = filename;
s = (char*)filename;
f = open(s, O_RDONLY);
if(s != filename)
free(s);

View file

@ -7,5 +7,5 @@ pause(void)
{
for(;;)
if(_SLEEP(1000*1000) < 0)
return;
return -1;
}

View file

@ -12,7 +12,7 @@ read(int d, void *buf, size_t nbytes)
int n, noblock, isbuf;
Fdinfo *f;
if(d<0 || d>=OPEN_MAX || !((f = &_fdinfo[d])->flags&FD_ISOPEN)){
if(d<0 || d>=OPEN_MAX || !(_fdinfo[d].flags & FD_ISOPEN)){
errno = EBADF;
return -1;
}

View file

@ -10,7 +10,7 @@
int
rename(const char *from, const char *to)
{
int n, i;
int n, ffd, tfd;
char *f, *t;
Dir *d, nd;
@ -31,45 +31,45 @@ rename(const char *from, const char *to)
}
f = strrchr(from, '/');
t = strrchr(to, '/');
f = f? f+1 : from;
t = t? t+1 : to;
n = 0;
f = f? f+1 : (char*)from;
t = t? t+1 : (char*)to;
if(f-from==t-to && strncmp(from, to, f-from)==0){
/* from and to are in same directory (we miss some cases) */
i = strlen(t);
_nulldir(&nd);
nd.name = t;
if(_dirwstat(from, &nd) < 0){
_syserrno();
n = -1;
return -1;
}
}else{
/* different directories: have to copy */
int ffd, tfd;
char buf[8192];
if((ffd = _OPEN(from, OREAD)) < 0 ||
(tfd = _CREATE(to, OWRITE, d->mode)) < 0){
_CLOSE(ffd);
_syserrno();
n = -1;
if((ffd = _OPEN(from, OREAD)) == -1)
goto err1;
if((tfd = _CREATE(to, OWRITE, d->mode)) == -1)
goto err2;
n = 0;
while(n>=0){
if((n = _READ(ffd, buf, sizeof(buf))) == -1)
goto err2;
if(_WRITE(tfd, buf, n) != n)
goto err2;
}
while(n>=0 && (n = _READ(ffd, buf, sizeof(buf))) > 0)
if(_WRITE(tfd, buf, n) != n){
_syserrno();
n = -1;
}
_CLOSE(ffd);
_CLOSE(tfd);
if(n>0)
n = 0;
if(n == 0) {
if(_REMOVE(from) < 0){
_syserrno();
return -1;
}
}
if(_REMOVE(from) < 0)
goto err2;
}
free(d);
return n;
return 0;
err2:
_CLOSE(tfd);
err1:
_CLOSE(ffd);
_syserrno();
free(d);
return -1;
}

View file

@ -7,7 +7,7 @@
*/
int
setgid(gid_t gid)
setgid(gid_t)
{
errno = EPERM;
return -1;

View file

@ -7,7 +7,7 @@
*/
int
setuid(uid_t uid)
setuid(uid_t)
{
errno = EPERM;
return -1;

View file

@ -107,7 +107,7 @@ _notehandler(Ureg *u, char *msg)
/* notetramp is machine-dependent; doesn't return to here */
}
_NOTED(0); /* NCONT */
return;
return 0;
}
}
_doatexits();

View file

@ -6,7 +6,7 @@
*/
int
sigsuspend(sigset_t *set)
sigsuspend(sigset_t *)
{
errno = EINVAL;
return -1;

View file

@ -87,7 +87,7 @@ tcgetattr(int fd, struct termios *t)
/* BUG: ignores optional actions */
int
tcsetattr(int fd, int optactions, const struct termios *t)
tcsetattr(int fd, int, const struct termios *t)
{
int n, i;
char buf[100];

View file

@ -7,7 +7,7 @@
*/
mode_t
umask(mode_t numask)
umask(mode_t)
{
return 0;
}

View file

@ -26,6 +26,7 @@ unlink(const char *path)
_syserrno();
return -1;
}
n = -1;
fd = -1;
for(i=0, f = _fdinfo;i < OPEN_MAX; i++, f++) {
if((f->flags&FD_ISOPEN) && (db2=_dirfstat(i)) != nil) {

View file

@ -49,7 +49,7 @@ pwdecode(char *p)
passwd.pw_dir = p;
p = pwskip(p);
passwd.pw_shell = p;
p = pwskip(p);
pwskip(p);
return(&passwd);
}

View file

@ -3,7 +3,7 @@
#include <errno.h>
int
mkfifo(char *path, mode_t mode)
mkfifo(char *, mode_t)
{
#pragma ref path
#pragma ref mode

View file

@ -14,4 +14,4 @@ OFILES=\
</sys/src/cmd/mksyslib
CFLAGS=-c -D_POSIX_SOURCE
CFLAGS=$CFLAGS -c -D_POSIX_SOURCE

View file

@ -4,7 +4,7 @@
#include <sys/limits.h>
long
pathconf(const char *path, int name)
pathconf(const char *, int name)
{
#pragma ref path
@ -46,10 +46,8 @@ pathconf(const char *path, int name)
}
long
fpathconf(int fd, int name)
fpathconf(int, int name)
{
#pragma ref fd
return pathconf(0, name);
}

View file

@ -20,6 +20,7 @@ tzset(void)
{
char *env, *p, *q;
env = NULL;
if((p = getenv("timezone")) == 0)
goto error;
if((env = malloc(strlen(p) + 1)) == 0)

View file

@ -509,7 +509,7 @@ _d2b(double darg, int *e, int *bits)
}
else
x[0] = y;
i = b->wds = (x[1] = z) ? 2 : 1;
b->wds = (x[1] = z) ? 2 : 1;
}
else {
#ifdef DEBUG
@ -518,7 +518,7 @@ _d2b(double darg, int *e, int *bits)
#endif
k = lo0bits(&z);
x[0] = z;
i = b->wds = 1;
b->wds = 1;
k += 32;
}
#else

View file

@ -27,7 +27,7 @@ int ftoa(double f, char *bp){
e1=e/2;
e2=e-e1;
p=f*pow10(e2);
while((g=p*pow10(e1))<1.) e1++;
while((p*pow10(e1))<1.) e1++;
while((g=p*pow10(e1))>=10.) --e1;
e=e1+e2;
f=g;

View file

@ -66,4 +66,4 @@ OFILES=\
</sys/src/cmd/mksyslib
CFLAGS=-c -D_POSIX_SOURCE
CFLAGS=$CFLAGS -c -D_POSIX_SOURCE

View file

@ -3,6 +3,7 @@
*/
#include "iolib.h"
#include <stdarg.h>
#include <stdint.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
@ -218,9 +219,8 @@ vfprintf(FILE *f, const char *s, va_list args)
}
static int
ocvt_c(FILE *f, va_list *args, int flags, int width, int precision)
ocvt_c(FILE *f, va_list *args, int flags, int width, int)
{
#pragma ref precision
int i;
if(!(flags&LEFT)) for(i=1; i<width; i++) putc(' ', f);
@ -269,11 +269,8 @@ ocvt_s(FILE *f, va_list *args, int flags, int width, int precision)
}
static int
ocvt_n(FILE *f, va_list *args, int flags, int width, int precision)
ocvt_n(FILE *, va_list *args, int flags, int, int)
{
#pragma ref f
#pragma ref width
#pragma ref precision
if(flags&SHORT)
*va_arg(*args, short *) = nprint;
else if(flags&LONG)
@ -307,7 +304,7 @@ ocvt_fixed(FILE *f, va_list *args, int flags, int width, int precision,
int nout, npad, nlzero;
if(sgned){
if(flags&PTR) snum = (long)va_arg(*args, void *);
if(flags&PTR) snum = (uintptr_t)va_arg(*args, void *);
else if(flags&SHORT) snum = va_arg(*args, short);
else if(flags&LONG) snum = va_arg(*args, long);
else if(flags&VLONG) snum = va_arg(*args, long long);
@ -323,7 +320,7 @@ ocvt_fixed(FILE *f, va_list *args, int flags, int width, int precision,
}
} else {
sign = "";
if(flags&PTR) num = (long)va_arg(*args, void *);
if(flags&PTR) num = (uintptr_t)va_arg(*args, void *);
else if(flags&SHORT) num = va_arg(*args, unsigned short);
else if(flags&LONG) num = va_arg(*args, unsigned long);
else if(flags&VLONG) num = va_arg(*args, unsigned long long);

View file

@ -60,7 +60,8 @@ icvt_x, 0, 0, 0, 0, 0, 0, 0, /* x y z { | } ~ ^? */
static int nread, ncvt;
static const char *fmtp;
int vfscanf(FILE *f, const char *s, va_list args){
int vfscanf(FILE *f, const char *s, va_list args)
{
int c, width, type, store;
nread=0;
ncvt=0;
@ -105,9 +106,10 @@ int vfscanf(FILE *f, const char *s, va_list args){
}
return ncvt;
}
static int icvt_n(FILE *f, va_list *args, int store, int width, int type){
#pragma ref f
#pragma ref width
static int
icvt_n(FILE *, va_list *args, int store, int, int type)
{
if(store){
--ncvt; /* this assignment doesn't count! */
switch(type){
@ -119,6 +121,7 @@ static int icvt_n(FILE *f, va_list *args, int store, int width, int type){
}
return 1;
}
#define SIGNED 1
#define UNSIGNED 2
#define POINTER 3
@ -132,7 +135,8 @@ static int icvt_n(FILE *f, va_list *args, int store, int width, int type){
* unsgned is SIGNED, UNSIGNED or POINTER, giving part of the type to store in;
* base is the number base -- if 0, C number syntax is used.
*/
static int icvt_fixed(FILE *f, va_list *args,
static int
icvt_fixed(FILE *f, va_list *args,
int store, int width, int type, int unsgned, int base){
unsigned long int num=0;
int sign=1, ndig=0, dig;
@ -211,26 +215,46 @@ Done:
}
return 1;
}
static int icvt_d(FILE *f, va_list *args, int store, int width, int type){
static int
icvt_d(FILE *f, va_list *args, int store, int width, int type)
{
return icvt_fixed(f, args, store, width, type, SIGNED, 10);
}
static int icvt_x(FILE *f, va_list *args, int store, int width, int type){
static int
icvt_x(FILE *f, va_list *args, int store, int width, int type)
{
return icvt_fixed(f, args, store, width, type, UNSIGNED, 16);
}
static int icvt_o(FILE *f, va_list *args, int store, int width, int type){
static int
icvt_o(FILE *f, va_list *args, int store, int width, int type)
{
return icvt_fixed(f, args, store, width, type, UNSIGNED, 8);
}
static int icvt_i(FILE *f, va_list *args, int store, int width, int type){
static int
icvt_i(FILE *f, va_list *args, int store, int width, int type)
{
return icvt_fixed(f, args, store, width, type, SIGNED, 0);
}
static int icvt_u(FILE *f, va_list *args, int store, int width, int type){
static int
icvt_u(FILE *f, va_list *args, int store, int width, int type)
{
return icvt_fixed(f, args, store, width, type, UNSIGNED, 10);
}
static int icvt_p(FILE *f, va_list *args, int store, int width, int type){
static int
icvt_p(FILE *f, va_list *args, int store, int width, int type)
{
return icvt_fixed(f, args, store, width, type, POINTER, 16);
}
#define NBUF 509
static int icvt_f(FILE *f, va_list *args, int store, int width, int type){
static int
icvt_f(FILE *f, va_list *args, int store, int width, int type)
{
char buf[NBUF+1];
char *s=buf;
int c, ndig=0, ndpt=0, nexp=1;
@ -278,11 +302,16 @@ Done:
}
return 1;
}
static int icvt_s(FILE *f, va_list *args, int store, int width, int type){
#pragma ref type
static int
icvt_s(FILE *f, va_list *args, int store, int width, int)
{
int c, nn;
register char *s;
if(store) s=va_arg(*args, char *);
char *s;
s = 0;
if(store)
s=va_arg(*args, char *);
do
c=ngetc(f);
while(isspace(c));
@ -298,7 +327,8 @@ static int icvt_s(FILE *f, va_list *args, int store, int width, int type){
else goto Done;
}
nn++;
if(store) *s++=c;
if(store)
*s++=c;
wgetc(c, f, Done);
}
nungetc(c, f);
@ -306,21 +336,27 @@ Done:
if(store) *s='\0';
return 1;
}
static int icvt_c(FILE *f, va_list *args, int store, int width, int type){
#pragma ref type
static int
icvt_c(FILE *f, va_list *args, int store, int width, int)
{
int c;
register char *s;
if(store) s=va_arg(*args, char *);
char *s;
s = 0;
if(store)
s=va_arg(*args, char *);
if(width<0) width=1;
for(;;){
wgetc(c, f, Done);
if(c==EOF) return 0;
if(store) *s++=c;
if(store)
*s++=c;
}
Done:
return 1;
}
static int match(int c, const char *pat){
static int match(int c, const char *pat)
{
int ok=1;
if(*pat=='^'){
ok=!ok;
@ -338,16 +374,20 @@ static int match(int c, const char *pat){
}
return !ok;
}
static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
#pragma ref type
static int
icvt_sq(FILE *f, va_list *args, int store, int width, int)
{
int c, nn;
register char *s;
register const char *pat;
pat=++fmtp;
char *s;
char *pat;
s = 0;
pat=(char*)++fmtp;
if(*fmtp=='^') fmtp++;
if(*fmtp!='\0') fmtp++;
while(*fmtp!='\0' && *fmtp!=']') fmtp++;
if(store) s=va_arg(*args, char *);
if(store)
s=va_arg(*args, char *);
nn=0;
for(;;){
wgetc(c, f, Done);
@ -356,8 +396,10 @@ static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
if(nn==0) return 0;
else goto Done;
}
if(!match(c, pat)) break;
if(store) *s++=c;
if(!match(c, pat))
break;
if(store)
*s++=c;
nn++;
}
nungetc(c, f);