shithub: riscv

Download patch

ref: a84a5c21ce23abfa3ab579f51d3152dcfc1ee1b3
parent: 417bdbb869597e171fd27384875c8fa6306e2311
author: cinap_lenrek <[email protected]>
date: Tue Dec 19 15:44:15 EST 2017

upas/fs: fix precedence bugs, compare digest pointer to nil

--- a/sys/src/cmd/upas/fs/cache.c
+++ b/sys/src/cmd/upas/fs/cache.c
@@ -319,7 +319,7 @@
 void
 digestmessage(Mailbox *mb, Message *m)
 {
-	assert(m->digest == 0);
+	assert(m->digest == nil);
 	m->digest = emalloc(SHA1dlen);
 	sha1((uchar*)m->start, m->end - m->start, m->digest, nil);
 	if(mtreeisdup(mb, m)){
@@ -351,7 +351,7 @@
 		m->size -= m->badchars;		/* sneaky */
 		m->ibadchars = m->badchars;
 	}
-	if(m->digest == 0)
+	if(m->digest == nil)
 		digestmessage(mb, m);
 	if(m->lines == 0)
 		m->lines = countlines(m);
@@ -396,7 +396,7 @@
 		msgdecref(mb, m);
 		return -1;
 	}
-	if(m->digest == 0)
+	if(m->digest == nil)
 		sysfatal("digest?");
 	countparts(m);
 	return 0;
--- a/sys/src/cmd/upas/fs/idx.c
+++ b/sys/src/cmd/upas/fs/idx.c
@@ -206,13 +206,13 @@
 validmessage(Mailbox *mb, Message *m, int level)
 {
 	if(level){
-		if(m->digest != 0)
+		if(m->digest != nil)
 			goto lose;
 		if(m->fileid <= 1000000ull<<8)
 		if(m->fileid != 0)
 			goto lose;
 	}else{
-		if(m->digest == 0)
+		if(m->digest == nil)
 			goto lose;
 		if(m->size == 0)
 			goto lose;
@@ -280,18 +280,17 @@
 static uchar*
 hackdigest(char *s)
 {
-	uchar t[SHA1dlen];
 	int i;
 
 	if(strcmp(s, "-") == 0)
-		return 0;
+		return nil;
 	if(strlen(s) != 2*SHA1dlen){
 		eprint("bad digest %s\n", s);
-		return 0;
+		return nil;
 	}
 	for(i = 0; i < SHA1dlen; i++)
-		t[i] = nibble(s[2*i])<<4 | nibble(s[2*i + 1]);
-	memmove(s, t, SHA1dlen);
+		((uchar*)s)[i] = nibble(s[2*i])<<4 | nibble(s[2*i + 1]);
+	s[i] = 0;
 	return (uchar*)s;
 }
 
@@ -342,8 +341,8 @@
 	ll = &parent->part;
 	nparts = npart;
 	for(; npart != 0 && (s = Brdstr(b, '\n', 1)); npart--){
-		m = 0;
-		digest = 0;
+		m = nil;
+		digest = nil;
 		n = tokenize(s, f, nelem(f));
 		if(n != Idxfields){
 dead:
@@ -357,11 +356,11 @@
 			continue;
 		}
 		digest = hackdigest(f[0]);
-		if(digest == 0 ^ level != 0)
-			goto dead;
-		if(level == 0)
+		if(level == 0){
+			if(digest == nil)
+				goto dead;
 			m = mtreefind(mb, digest);
-		else
+		} else
 			m = findmessage(mb, parent, nparts - npart);
 		if(m){
 			/*
--- a/sys/src/cmd/upas/fs/mtree.c
+++ b/sys/src/cmd/upas/fs/mtree.c
@@ -18,7 +18,7 @@
 	Mtree t;
 
 	assert(Topmsg(mb, m) && m->digest);
-	if(!m->digest)
+	if(m->digest == nil)
 		return 0;
 	memset(&t, 0, sizeof t);
 	t.m = m;
--- a/sys/src/cmd/upas/fs/plan9.c
+++ b/sys/src/cmd/upas/fs/plan9.c
@@ -127,7 +127,7 @@
 	if(m->size > Maxmsg)
 		return -1;
 	m->bend = m->rbend = m->end;
-	if(m->digest == 0)
+	if(m->digest == nil)
 		digestmessage(mb, m);
 	return 0;
 }