all: fix or silence various gcc warnings

As usual, gcc finds some real problems but also reports a ton
of noise. Fix the problems and quiet the noise.
This commit is contained in:
Russ Cox 2020-01-12 15:05:40 -05:00 committed by Russ Cox
parent fa325e9b42
commit fafa622a5b
17 changed files with 27 additions and 22 deletions

4
bin/9c
View file

@ -14,6 +14,10 @@ usegcc()
-Wno-comment \ -Wno-comment \
-Wno-sign-compare \ -Wno-sign-compare \
-Wno-unknown-pragmas \ -Wno-unknown-pragmas \
-Wno-misleading-indentation \
-Wno-stringop-truncation \
-Wno-stringop-overflow \
-Wno-format-truncation \
-fno-omit-frame-pointer \ -fno-omit-frame-pointer \
-fsigned-char \ -fsigned-char \
" "

View file

@ -290,6 +290,8 @@ p9crresp(ServerState *s, uchar *resp, int resplen)
Ticket t; Ticket t;
Ticketreq tr; Ticketreq tr;
memset(&tr, 0, sizeof tr); // TODO: what should tr be initialized to?
if(xiowrite(s->asfd, resp, resplen) != resplen) if(xiowrite(s->asfd, resp, resplen) != resplen)
return -1; return -1;

View file

@ -1142,7 +1142,7 @@ textedit(Thing *t, char *tag)
fc = f->info; fc = f->info;
for(i=0; i<=w && i<=f->n; i++) for(i=0; i<=w && i<=f->n; i++)
nfc[i] = fc[i]; nfc[i] = fc[i];
if(w+1 < i) if(i < w+1)
memset(nfc+i, 0, ((w+1)-i)*sizeof(Fontchar)); memset(nfc+i, 0, ((w+1)-i)*sizeof(Fontchar));
x = fc[f->n].x; x = fc[f->n].x;
for(; i<=w; i++) for(; i<=w; i++)

View file

@ -257,7 +257,7 @@ trans(int c, char *p1)
char *pad(int n) /* return the padding as a string */ char *pad(int n) /* return the padding as a string */
{ {
static char buf[20]; static char buf[30];
buf[0] = 0; buf[0] = 0;
if (n < 0) { if (n < 0) {

View file

@ -35,7 +35,7 @@ void coordlog(int n) /* remember log scaling */
void coord(Obj *p) /* set coord range */ void coord(Obj *p) /* set coord range */
{ {
static char buf[10]; static char buf[20];
ncoord++; ncoord++;
if (ncoord > 1 && strcmp(p->name, dflt_coord) == 0) { if (ncoord > 1 && strcmp(p->name, dflt_coord) == 0) {

View file

@ -202,7 +202,7 @@ atimes(char *ar)
name[namelen] = 0; name[namelen] = 0;
namelen = 0; namelen = 0;
}else{ }else{
strncpy(name, h.name, sizeof(h.name)); memmove(name, h.name, sizeof(h.name));
for(i = sizeof(h.name)-1; i > 0 && name[i] == ' '; i--) for(i = sizeof(h.name)-1; i > 0 && name[i] == ' '; i--)
; ;
if(name[i] == '/') /* system V bug */ if(name[i] == '/') /* system V bug */

View file

@ -78,6 +78,7 @@ eenter(char *ask, char *buf, int len, Mouse *m)
b = screen; b = screen;
sc = b->clipr; sc = b->clipr;
replclipr(b, 0, b->r); replclipr(b, 0, b->r);
t = ZP;
while(!done){ while(!done){
p = stringsize(font, buf ? buf : ""); p = stringsize(font, buf ? buf : "");

View file

@ -435,7 +435,7 @@ double errcheck(double x, char *s)
return x; return x;
} }
char errbuf[200]; char errbuf[1000];
void eprint(void); void eprint(void);

View file

@ -9,7 +9,7 @@
extern void yyerror(char *); extern void yyerror(char *);
extern char errbuf[200]; extern char errbuf[1000];
#undef sprintf /* Snow Leopard */ #undef sprintf /* Snow Leopard */

View file

@ -68,7 +68,7 @@ Time time;
unsigned long min; unsigned long min;
unsigned long hr; unsigned long hr;
unsigned long day; unsigned long day;
static char buffer[32]; static char buffer[50];
msec = time % 1000; msec = time % 1000;
time /= 1000; time /= 1000;

View file

@ -435,7 +435,7 @@ double errcheck(double x, char *s)
return x; return x;
} }
char errbuf[200]; char errbuf[1000];
void eprint(void); void eprint(void);

View file

@ -9,7 +9,7 @@
extern void yyerror(char *); extern void yyerror(char *);
extern char errbuf[200]; extern char errbuf[1000];
#undef sprintf /* Snow Leopard */ #undef sprintf /* Snow Leopard */

View file

@ -438,7 +438,7 @@ errcheck(double x, char *s)
return x; return x;
} }
char errbuf[200]; char errbuf[1000];
void void
yyerror(char *s) yyerror(char *s)

View file

@ -11,7 +11,7 @@
#define dprintf if(dbg)printf #define dprintf if(dbg)printf
extern char errbuf[200]; extern char errbuf[1000];
#undef sprintf /* Snow Leopard */ #undef sprintf /* Snow Leopard */

View file

@ -723,15 +723,15 @@ setfp(int pos, int f, char *truename, int print) /* mount font f at position pos
else else
strcpy(shortname, (char *) unpair(f)); strcpy(shortname, (char *) unpair(f));
if (truename && strrchr(truename, '/')) { /* .fp 1 R dir/file: use verbatim */ if (truename && strrchr(truename, '/')) { /* .fp 1 R dir/file: use verbatim */
sprintf(pathname, "%s", truename); snprintf(pathname, NS, "%s", truename);
if (fonts[pos].truename) if (fonts[pos].truename)
free(fonts[pos].truename); free(fonts[pos].truename);
fonts[pos].truename = strdupl(truename); fonts[pos].truename = strdupl(truename);
} else if (truename) { /* synonym: .fp 1 R Avant */ } else if (truename) { /* synonym: .fp 1 R Avant */
sprintf(pathname, "%s/dev%s/%s", fontdir, devname, truename); snprintf(pathname, NS, "%s/dev%s/%s", fontdir, devname, truename);
truename = 0; /* so doesn't get repeated by ptfpcmd */ truename = 0; /* so doesn't get repeated by ptfpcmd */
} else /* vanilla: .fp 5 XX */ } else /* vanilla: .fp 5 XX */
sprintf(pathname, "%s/dev%s/%s", fontdir, devname, shortname); snprintf(pathname, NS, "%s/dev%s/%s", fontdir, devname, shortname);
if (truename == 0 && fonts[pos].truename != 0) { if (truename == 0 && fonts[pos].truename != 0) {
free(fonts[pos].truename); free(fonts[pos].truename);
fonts[pos].truename = 0; fonts[pos].truename = 0;

View file

@ -72,7 +72,7 @@ p9dialparse(char *addr, char **pnet, char **punix, void *phost, int *pport)
if((port = strchr(host, '!')) == nil){ if((port = strchr(host, '!')) == nil){
if(strcmp(net, "unix")==0 || strcmp(net, "net")==0){ if(strcmp(net, "unix")==0 || strcmp(net, "net")==0){
Unix: Unix:
if(strlen(host)+1 > sizeof ((struct sockaddr_un*)&ss)->sun_path){ if(strlen(host)+1 > sizeof ((struct sockaddr_un*)ss)->sun_path){
werrstr("unix socket name too long"); werrstr("unix socket name too long");
return -1; return -1;
} }

View file

@ -63,17 +63,15 @@ p9lrand(void)
lock(&lk); lock(&lk);
rng_tap--; if(rng_tap <= rng_vec) {
if(rng_tap < rng_vec) { if(rng_feed == 0)
if(rng_feed == 0) {
isrand(1); isrand(1);
rng_tap--;
}
rng_tap += LEN; rng_tap += LEN;
} }
rng_feed--; rng_tap--;
if(rng_feed < rng_vec) if(rng_feed <= rng_vec)
rng_feed += LEN; rng_feed += LEN;
rng_feed--;
x = (*rng_feed + *rng_tap) & MASK; x = (*rng_feed + *rng_tap) & MASK;
*rng_feed = x; *rng_feed = x;