shithub: riscv

Download patch

ref: 2de164c51dc3330859c160b80440e1363fb5b566
parent: 5d7e9bee3ce75cce5727c0283a192b344800cc07
author: Ori Bernstein <[email protected]>
date: Sat Apr 25 06:43:39 EDT 2020

fix typos in time calculation

the results of the time calculation were garbled -- and
apparently negative on my system when testing, so the
test passed when it shouldn't have.

--- a/sys/src/cmd/6c/txt.c
+++ b/sys/src/cmd/6c/txt.c
@@ -363,6 +363,7 @@
 			if(reg[i] == 0 && !resvreg[i])
 				goto out;
 		diag(tn, "out of float registers");
+		abort();
 		goto out;
 	}
 	diag(tn, "unknown type in regalloc: %T", tn->type);
--- a/sys/src/cmd/aux/getflags.c
+++ b/sys/src/cmd/aux/getflags.c
@@ -26,9 +26,13 @@
 char*
 argname(char *p)
 {
+	char *s;
 	Rune r;
 	int n;
 
+	s = p;
+	if(*p == ' ')
+		p++;
 	while(1){
 		n = chartorune(&r, p);
 		if(!isalpharune(r) && !isdigitrune(r))
@@ -35,6 +39,8 @@
 			break;
 		p += n;
 	}
+	if(*s == ' ')
+		return s;
 	return p;
 }
 
--- a/sys/src/cmd/cpp/macro.c
+++ b/sys/src/cmd/cpp/macro.c
@@ -350,7 +350,7 @@
 void
 substargs(Nlist *np, Tokenrow *rtr, Tokenrow **atr)
 {
-	Tokenrow ttr;
+	Tokenrow ttr, rp, rn;
 	Token *tp, *ap, *an, *pp, *pn;
 	int ntok, argno, hs;
 
@@ -369,19 +369,25 @@
 			insertrow(rtr, ntok, stringify(atr[argno]));
 		} else if (ispaste(rtr, &ap, &an, &ntok)) { /* first token, just do the next one */
 			pp = ap;
+			rp.tp = nil;
 			pn = an;
+			rn.tp = nil;
 			if (ap && (argno = lookuparg(np, ap)) >= 0){
 				pp = nil;
-				if(atr[argno]->tp != atr[argno]->lp)
-					pp = atr[argno]->lp - 1;
+				rp = *atr[argno];
+				if(rp.tp != rp.lp)
+					pp = --rp.lp;
 			}
 			if (an && (argno = lookuparg(np, an)) >= 0) {
 				pn = nil;
-				if(atr[argno]->tp != atr[argno]->lp)
-					pn = atr[argno]->lp - 1;
+				rn = *atr[argno];
+				if(rn.tp != rn.lp)
+					pn = rn.bp++;
 			}
 			glue(&ttr, pp, pn);
+			insertrow(rtr, 0, &rp);
 			insertrow(rtr, ntok, &ttr);
+			insertrow(rtr, 0, &rn);
 			free(ttr.bp);
 		} else if (rtr->tp->type==NAME) {
 			if((argno = lookuparg(np, rtr->tp)) >= 0) {
--- a/sys/src/cmd/cpp/test.c
+++ b/sys/src/cmd/cpp/test.c
@@ -21,6 +21,9 @@
 #define FOO	CAT(BAR, 3)
 FOO
 
+/* Expected: a bc d */
+CAT(a b, c d)
+
 /*
  * CURRENTLY BROKEN:
  *     __VA_ARGS__ requires at least one item.
@@ -58,4 +61,4 @@
  *     It should treat no args as a single empty arg list.
 p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
 char c[2][6] = { str(hello), str() };
-*/
\ No newline at end of file
+*/
--- a/sys/src/cmd/dossrv/dosfs.c
+++ b/sys/src/cmd/dossrv/dosfs.c
@@ -550,7 +550,7 @@
 /*
  * wipe out a dos directory entry
  */
-static void
+static int
 doremove(Xfs *xf, Dosptr *dp)
 {
 	Iosect *p;
@@ -565,6 +565,8 @@
 	}
 	if(prevdo < 0 && dp->prevaddr != -1){
 		p = getsect(xf, dp->prevaddr);
+		if(p == nil)
+			return -1;
 		for(prevdo = ((Dosbpb*)xf->ptr)->sectsize-DOSDIRSIZE; prevdo >= 0; prevdo -= DOSDIRSIZE){
 			if(p->iobuf[prevdo+11] != 0xf)
 				break;
@@ -572,7 +574,8 @@
 			p->flags |= BMOD;
 		}
 		putsect(p);
-	}		
+	}
+	return 0;		
 }
 
 void
@@ -601,8 +604,7 @@
 	 * or it's a read only file in the root directory
 	 */
 	parp = getsect(f->xf, dp->paddr);
-	if(parp == nil
-	|| getfile(f) < 0){
+	if(parp == nil || getfile(f) < 0){
 		errno = Eio;
 		goto out;
 	}
@@ -617,7 +619,10 @@
 		errno = Eio;
 		goto out;
 	}
-	doremove(f->xf, f->ptr);
+	if(doremove(f->xf, f->ptr) == -1){
+		errno = Eio;
+		goto out;
+	}
 	if(!isroot(dp->paddr)){
 		puttime(pard, 0);
 		parp->flags |= BMOD;
--- a/sys/src/cmd/dossrv/dossubs.c
+++ b/sys/src/cmd/dossrv/dossubs.c
@@ -1000,6 +1000,8 @@
 			c = count;
 		if(c == bp->sectsize){
 			p = getosect(xf, addr);
+			if(p == nil)
+				return -1;
 			p->flags = 0;
 		}else{
 			p = getsect(xf, addr);
@@ -1632,7 +1634,8 @@
 			if(rp == nil)
 				return -1;
 			wp = getosect(xf, ws);
-			assert(wp != nil);
+			if(wp == nil)
+				return -1;
 			memmove(wp->iobuf, rp->iobuf, bp->sectsize);
 			wp->flags = BMOD;
 			putsect(rp);
@@ -1702,6 +1705,8 @@
 	k = clust2sect(bp, n);
 	for(i=0; i<bp->clustsize; i++){
 		p = getosect(xf, k+i);
+		if(p == nil)
+			return -1;
 		memset(p->iobuf, 0, bp->sectsize);
 		p->flags = BMOD;
 		putsect(p);
--- a/sys/src/cmd/dossrv/iotrack.c
+++ b/sys/src/cmd/dossrv/iotrack.c
@@ -39,8 +39,11 @@
 	int toff;
 	Iosect *p;
 
-	if(addr < 0)
+	if(addr < 0){
+		chat("invalid address\n");
+		errno = Eio;
 		return nil;
+	}
 	toff = addr % Sect2trk;
 	taddr = addr - toff;
 	t = getiotrack(xf, taddr);
@@ -53,8 +56,10 @@
 	}
 	t->ref++;
 	p = t->tp->p[toff];
-	if(p == 0){
+	if(p == nil){
 		p = newsect();
+		if(p == nil)
+			return nil;
 		t->tp->p[toff] = p;
 		p->flags = t->flags&BSTALE;
 		p->lock.key = 0;
@@ -196,10 +201,10 @@
 			t->flags &= ~BSTALE;
 	}
 	if(devwrite(t->xf, t->addr, t->tp->buf, Trksize) < 0){
-		chat("error]");
+		chat("error]\n");
 		return -1;
 	}
-	chat(" done]");
+	chat(" done]\n");
 	return 0;
 }
 
@@ -304,6 +309,8 @@
 	else
 		p = malloc(sizeof(Iosect));
 	unmlock(&freelock);
+	if(p == nil)
+		return nil;
 	p->next = 0;
 	return p;
 }
--- a/sys/src/cmd/plumb/plumb.c
+++ b/sys/src/cmd/plumb/plumb.c
@@ -35,29 +35,50 @@
 	}
 }
 
+int
+matchmsg(Plumbmsg *m, Plumbmsg *pat)
+{
+	Plumbattr *a;
+	char *v;
+
+	if(pat->src && strcmp(m->src, pat->src) != 0)
+		return 0;
+	if(pat->dst && strcmp(m->dst, pat->dst) != 0)
+		return 0;
+	if(pat->wdir && strcmp(m->wdir, pat->wdir) != 0)
+		return 0;
+	if(pat->type && strcmp(m->type, pat->type) != 0)
+		return 0;
+	for(a = m->attr; a != nil; a = a->next){
+		v = plumblookup(pat->attr, a->name);
+		if(v != nil && strcmp(a->value, v) != 0)
+			return 0;
+	}
+	return 1;
+}
+
 void
 main(int argc, char *argv[])
 {
-	char buf[1024], *p;
+	char buf[1024], *p, *readport;
 	int fd, i, input;
+	Plumbmsg *rmsg;
+	Plumbattr *a;
 
 	input = 0;
-	m.src = "plumb";
+	readport = nil;
+	m.src = nil;
 	m.dst = nil;
-	m.wdir = getwd(buf, sizeof buf);
+	m.wdir = nil;
 	m.type = "text";
 	m.attr = nil;
 	ARGBEGIN{
 	case 'a':
-		p = ARGF();
-		if(p == nil)
-			usage();
+		p = EARGF(usage());
 		m.attr = plumbaddattr(m.attr, plumbunpackattr(p));
 		break;
 	case 'd':
-		m.dst = ARGF();
-		if(m.dst == nil)
-			usage();
+		m.dst = EARGF(usage());
 		break;
 	case 'i':
 		input++;
@@ -64,30 +85,27 @@
 		break;
 	case 't':
 	case 'k':	/* for backwards compatibility */
-		m.type = ARGF();
-		if(m.type == nil)
-			usage();
+		m.type = EARGF(usage());
 		break;
 	case 'p':
-		plumbfile = ARGF();
-		if(plumbfile == nil)
-			usage();
+		plumbfile = EARGF(usage());
 		break;
 	case 's':
-		m.src = ARGF();
-		if(m.src == nil)
-			usage();
+		m.src = EARGF(usage());
 		break;
 	case 'w':
-		m.wdir = ARGF();
-		if(m.wdir == nil)
-			usage();
+		m.wdir = EARGF(usage());
 		break;
+	case 'r':
+		readport = EARGF(usage());
+		break;
 	}ARGEND
 
-	if((input && argc>0) || (!input && argc<1))
+	if((input && argc>0) || (!input && argc<1) && readport == nil)
 		usage();
-	if(plumbfile != nil)
+	if(readport != nil)
+		fd = plumbopen(readport, OREAD);
+	else if(plumbfile != nil)
 		fd = open(plumbfile, OWRITE);
 	else
 		fd = plumbopen("send", OWRITE);
@@ -95,6 +113,30 @@
 		fprint(2, "plumb: can't open plumb file: %r\n");
 		exits("open");
 	}
+	if(readport != nil){
+again:
+		rmsg = plumbrecv(fd);
+		if(rmsg == nil){
+			fprint(2, "plumb: receive failed: %r\n");
+			exits("recv");
+		}
+		print("got message, matching\n");
+		if(!matchmsg(rmsg, &m))
+			goto again;
+		print("src %s\n", rmsg->src);
+		print("dst %s\n", rmsg->dst);
+		print("wdir %s\n", rmsg->wdir);
+		print("type %s\n", rmsg->type);
+		print("data %.*s\n", rmsg->ndata, rmsg->data);
+		for(a = rmsg->attr; a; a = a->next)
+			print("attr %s=%s\n", a->name, a->value);
+		plumbfree(rmsg);
+		exits(nil);
+	}
+	if(m.src == nil)
+		m.src = "plumb";
+	if(m.wdir == nil)
+		m.wdir = getwd(buf, sizeof buf);
 	if(input){
 		gather();
 		if(plumblookup(m.attr, "action") == nil)
--- a/sys/src/cmd/samterm/flayer.c
+++ b/sys/src/cmd/samterm/flayer.c
@@ -258,7 +258,7 @@
 
 	if(l->visible!=All)
 		flupfront(l);
-	dt = l->click = mousep->msec;
+	dt = mousep->msec - l->click;
 	dx = abs(mousep->xy.x - clickpt.x);
 	dy = abs(mousep->xy.y - clickpt.y);
 
@@ -279,7 +279,6 @@
 {
 	ulong fp0, fp1;
 
-	l->click = 0;
 	if(l->visible==None || !flprepare(l)){
 		l->p0 = p0, l->p1 = p1;
 		return;