Amazingly picky bug fixes from Valgrind.

This commit is contained in:
rsc 2004-03-05 05:53:11 +00:00
parent 230d62c475
commit 15680d56a6
9 changed files with 20 additions and 9 deletions

View file

@ -298,7 +298,7 @@ tgetc(void *a, uint n)
Rune* Rune*
skipbl(Rune *r, int n, int *np) skipbl(Rune *r, int n, int *np)
{ {
while(n>0 && *r==' ' || *r=='\t' || *r=='\n'){ while(n>0 && (*r==' ' || *r=='\t' || *r=='\n')){
--n; --n;
r++; r++;
} }
@ -309,7 +309,7 @@ skipbl(Rune *r, int n, int *np)
Rune* Rune*
findbl(Rune *r, int n, int *np) findbl(Rune *r, int n, int *np)
{ {
while(n>0 && *r!=' ' && *r!='\t' && *r!='\n'){ while(n>0 && (*r!=' ' && *r!='\t' && *r!='\n')){
--n; --n;
r++; r++;
} }

View file

@ -29,14 +29,18 @@ void
threadmain(int argc, char *argv[]) threadmain(int argc, char *argv[])
{ {
char buf[512]; char buf[512];
int fd; int fd, dofork;
progname = "plumber"; progname = "plumber";
dofork = 1;
ARGBEGIN{ ARGBEGIN{
case 'd': case 'd':
debug = 1; debug = 1;
break; break;
case 'f':
dofork = 0;
break;
case 'p': case 'p':
plumbfile = ARGF(); plumbfile = ARGF();
break; break;
@ -66,6 +70,7 @@ threadmain(int argc, char *argv[])
* Start all processes and threads from other proc * Start all processes and threads from other proc
* so we (main pid) can return to user. * so we (main pid) can return to user.
*/ */
if(dofork)
switch(fork()){ switch(fork()){
case -1: case -1:
sysfatal("fork: %r"); sysfatal("fork: %r");

View file

@ -741,6 +741,7 @@ morerules(uchar *text, int done)
; ;
while((rs=readruleset()) != nil){ while((rs=readruleset()) != nil){
rules = erealloc(rules, (n+2)*sizeof(Ruleset*)); rules = erealloc(rules, (n+2)*sizeof(Ruleset*));
fprint(2, "initialize rules %d %d\n", n, n+1);
rules[n++] = rs; rules[n++] = rs;
rules[n] = nil; rules[n] = nil;
} }

View file

@ -28,7 +28,7 @@ cachechars(Font *f, char **ss, Rune **rr, ushort *cp, int max, int *wp, char **s
} }
wid = 0; wid = 0;
*subfontname = 0; *subfontname = 0;
for(i=0; (*sp || *rp) && i<max; sp+=w, rp+=rw){ for(i=0; i<max && (*sp || *rp); sp+=w, rp+=rw){
if(ss){ if(ss){
r = *(uchar*)sp; r = *(uchar*)sp;
if(r < Runeself) if(r < Runeself)

View file

@ -25,7 +25,7 @@ _stringnwidth(Font *f, char *s, Rune *r, int len)
}else }else
rptr = &r; rptr = &r;
twid = 0; twid = 0;
while((*s || *r) && len){ while(len && (*s || *r)){
max = Max; max = Max;
if(len < max) if(len < max)
max = len; max = len;

View file

@ -115,9 +115,12 @@ static
void void
chopbox(Frame *f, Frbox *b, int n) /* drop first n chars; no allocation done */ chopbox(Frame *f, Frbox *b, int n) /* drop first n chars; no allocation done */
{ {
char *p;
if(b->nrune<0 || b->nrune<n) if(b->nrune<0 || b->nrune<n)
drawerror(f->display, "chopbox"); drawerror(f->display, "chopbox");
strcpy((char*)b->ptr, (char*)runeindex(b->ptr, n)); p = (char*)runeindex(b->ptr, n);
memmove((char*)b->ptr, p, strlen(p)+1);
b->nrune -= n; b->nrune -= n;
b->wid = stringwidth(f->font, (char *)b->ptr); b->wid = stringwidth(f->font, (char *)b->ptr);
} }

View file

@ -28,7 +28,8 @@ fprint(2, "n %d msize %d\n", n, msize);
tx.offset = offset; tx.offset = offset;
tx.count = n; tx.count = n;
fsrpc(fid->fs, &tx, &rx, &freep); if(fsrpc(fid->fs, &tx, &rx, &freep) < 0)
return -1;
if(rx.type == Rerror){ if(rx.type == Rerror){
werrstr("%s", rx.ename); werrstr("%s", rx.ename);
free(freep); free(freep);

View file

@ -24,7 +24,8 @@ _fspwrite(Fid *fid, void *buf, long n, vlong offset)
tx.count = n; tx.count = n;
tx.data = buf; tx.data = buf;
fsrpc(fid->fs, &tx, &rx, &freep); if(fsrpc(fid->fs, &tx, &rx, &freep) < 0)
return -1;
if(rx.type == Rerror){ if(rx.type == Rerror){
werrstr("%s", rx.ename); werrstr("%s", rx.ename);
free(freep); free(freep);

View file

@ -45,7 +45,7 @@ main(int argc, char **argv)
signal(SIGTERM, _threaddie); signal(SIGTERM, _threaddie);
signal(SIGCHLD, _nop); signal(SIGCHLD, _nop);
signal(SIGINFO, _threadstatus); // signal(SIGINFO, _threadstatus);
// rfork(RFREND); // rfork(RFREND);
//_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0; //_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;