warnings: fix warnings on newer compilers

Mostly turning the crank on fixing simple warnings: arrays, for
instance, can never be nil.  A couple of pointers should have been
initialized to `nil` before being tested.

Some logic in `troff` was simplified: basically, an `if` statement had
a condition that must have always been true if that section of code
were being executed at all.
This commit is contained in:
Dan Cross
2025-07-24 14:22:18 +00:00
parent 564d45b5a5
commit 4089e29e89
5 changed files with 21 additions and 15 deletions

View File

@@ -177,8 +177,8 @@ loadfontname(int n, char *s)
if (strcmp(s, fname[n]) == 0) if (strcmp(s, fname[n]) == 0)
return; return;
if(fname[n] && fname[n][0]){ if(fname[n][0]){
if(lastload[n] && strcmp(lastload[n], fname[n]) == 0) if(strcmp(lastload[n], fname[n]) == 0)
return; return;
strcpy(lastload[n], fname[n]); strcpy(lastload[n], fname[n]);
} }

View File

@@ -985,7 +985,7 @@ trypref(char* ep, char* a, int lev, int flag)
deriv[lev+1].type += PREF; deriv[lev+1].type += PREF;
h = tryword(bp,ep,lev+1,flag); h = tryword(bp,ep,lev+1,flag);
if(Set(h,NOPREF) || if(Set(h,NOPREF) ||
((tp->flag&IN) && inun(bp-2,h)==0)) { ((tp->flag&IN) && bp>=(word+2) && inun(bp-2,h)==0)) {
h = 0; h = 0;
break; break;
} }

View File

@@ -71,7 +71,7 @@ putline(int i, int nl)
ss = table[nl][c].col; ss = table[nl][c].col;
if (ss == 0) if (ss == 0)
continue; continue;
if(font[c][stynum[nl]]) if(c < MAXHEAD && 0 <= nl && nl < 2)
chfont = 1; chfont = 1;
if (point(ss) ) if (point(ss) )
continue; continue;

View File

@@ -1,5 +1,6 @@
#define _BSD_SOURCE 1 /* isascii */ #define _BSD_SOURCE 1 /* isascii */
#define _DEFAULT_SOURCE 1 #define _DEFAULT_SOURCE 1
#include <u.h>
#include "tdef.h" #include "tdef.h"
#include "fns.h" #include "fns.h"
#include "ext.h" #include "ext.h"
@@ -323,13 +324,14 @@ void ckul(void)
void storeline(Tchar c, int w) void storeline(Tchar c, int w)
{ {
int diff; int diff;
Tchar *nline;
if (linep >= line + lnsize - 2) { if (linep >= line + lnsize - 2) {
lnsize += LNSIZE; lnsize += LNSIZE;
diff = linep - line; diff = linep - line;
if (( line = (Tchar *)realloc((char *)line, lnsize * sizeof(Tchar))) != NULL) { if ((nline = (Tchar *)realloc((char *)line, lnsize * sizeof(Tchar))) != NULL) {
if (linep && diff) line = nline;
linep = line + diff; linep = line + diff;
} else { } else {
if (over) { if (over) {
return; return;
@@ -767,24 +769,26 @@ rtn:
void storeword(Tchar c, int w) void storeword(Tchar c, int w)
{ {
Tchar *savp; Tchar *nword;
uintptr savp;
int i; int i;
if (wordp >= word + wdsize - 2) { if (wordp >= word + wdsize - 2) {
wdsize += WDSIZE; wdsize += WDSIZE;
savp = word; savp = (uintptr)word;
if (( word = (Tchar *)realloc((char *)word, wdsize * sizeof(Tchar))) != NULL) { if ((nword = (Tchar *)realloc((char *)word, wdsize * sizeof(Tchar))) != NULL) {
word = nword;
if (wordp) if (wordp)
wordp = word + (wordp - savp); wordp = word + ((uintptr)wordp - savp);
if (pendw) if (pendw)
pendw = word + (pendw - savp); pendw = word + ((uintptr)pendw - savp);
if (wdstart) if (wdstart)
wdstart = word + (wdstart - savp); wdstart = word + ((uintptr)wdstart - savp);
if (wdend) if (wdend)
wdend = word + (wdend - savp); wdend = word + ((uintptr)wdend - savp);
for (i = 0; i < NHYP; i++) for (i = 0; i < NHYP; i++)
if (hyptr[i]) if (hyptr[i])
hyptr[i] = word + (hyptr[i] - savp); hyptr[i] = word + ((uintptr)hyptr[i] - savp);
} else { } else {
if (over) { if (over) {
return; return;

View File

@@ -304,9 +304,11 @@ plumbunpackpartial(char *buf, int n, int *morep)
i = plumbline(&m->dst, buf, i, n, &bad); i = plumbline(&m->dst, buf, i, n, &bad);
i = plumbline(&m->wdir, buf, i, n, &bad); i = plumbline(&m->wdir, buf, i, n, &bad);
i = plumbline(&m->type, buf, i, n, &bad); i = plumbline(&m->type, buf, i, n, &bad);
attr = nil;
i = plumbline(&attr, buf, i, n, &bad); i = plumbline(&attr, buf, i, n, &bad);
m->attr = plumbunpackattr(attr); m->attr = plumbunpackattr(attr);
free(attr); free(attr);
ntext = nil;
i = plumbline(&ntext, buf, i, n, &bad); i = plumbline(&ntext, buf, i, n, &bad);
m->ndata = atoi(ntext); m->ndata = atoi(ntext);
if(m->ndata != n-i){ if(m->ndata != n-i){