shithub: riscv

Download patch

ref: 5ec91a6413dbf87a9fc0aa3e8038d81d2054bb0a
parent: 2e5cd278d75be0cc046ac66259cc8d20af04b0c8
author: cinap_lenrek <[email protected]>
date: Sun Feb 24 22:39:31 EST 2019

upas/fs: fix %.*s format usage

--- a/sys/src/cmd/upas/fs/imap.c
+++ b/sys/src/cmd/upas/fs/imap.c
@@ -591,9 +591,8 @@
 	if(n == -1)
 		return "cannot find IMAP password";
 	for(i = 0; i < n; i++)
-		if(rbuf[i] >= 'A' && rbuf[i] <= 'Z')
-			rbuf[i] += 'a' - 'A';
-	l = snprint(ubuf, sizeof ubuf, "%s %.*s", usr, n, rbuf);
+		rbuf[i] = tolower(rbuf[i]);
+	l = snprint(ubuf, sizeof ubuf, "%s %.*s", usr, utfnlen(rbuf, n), rbuf);
 	idprint(imap, "raw cram [%s]\n", ubuf);
 	snprint(ebuf, sizeof ebuf, "%.*[", l, ubuf);
 
--- a/sys/src/cmd/upas/fs/mdir.c
+++ b/sys/src/cmd/upas/fs/mdir.c
@@ -26,10 +26,8 @@
 parseunix(Message *m)
 {
 	char *s, *p;
-	int l;
 
-	l = m->header - m->start;
-	m->unixheader = smprint("%.*s", l, m->start);
+	m->unixheader = smprint("%.*s", utfnlen(m->start, m->header - m->start), m->start);
 	s = m->start + 5;
 	if((p = strchr(s, ' ')) == nil)
 		return;
--- a/sys/src/cmd/upas/fs/plan9.c
+++ b/sys/src/cmd/upas/fs/plan9.c
@@ -46,7 +46,7 @@
 
 	r = chkunix0(s, n);
 	if(r == -1)
-		eprint("plan9: warning naked from [%.*s]\n", n, s);
+		eprint("plan9: warning naked from [%.*s]\n", utfnlen(s, n), s);
 	return r;
 }
 
@@ -54,11 +54,9 @@
 parseunix(Message *m)
 {
 	char *s, *p, *q;
-	int l;
 	Tm tm;
 
-	l = m->header - m->start;
-	m->unixheader = smprint("%.*s", l, m->start);
+	m->unixheader = smprint("%.*s", utfnlen(m->start, m->header - m->start), m->start);
 	s = m->start + 5;
 	if((p = strchr(s, ' ')) == nil)
 		return s;
--- a/sys/src/cmd/upas/fs/pop3.c
+++ b/sys/src/cmd/upas/fs/pop3.c
@@ -182,7 +182,7 @@
 		if(s = pop3capa(pop))
 			return s;
 
-		pop3cmd(pop, "APOP %s %.*s", user, n, buf);
+		pop3cmd(pop, "APOP %s %.*s", user, utfnlen(buf, n), buf);
 		if(!isokay(s = pop3resp(pop)))
 			return s;
 
--- a/sys/src/cmd/upas/fs/strtotm.c
+++ b/sys/src/cmd/upas/fs/strtotm.c
@@ -85,7 +85,7 @@
 				tm.year = j - 1900;
 			continue;
 		}
-		//eprint("strtotm: garbage %.*s\n", q - p, p);
+		//eprint("strtotm: garbage %.*s\n", utfnlen(p, q - p), p);
 	}
 	if(tm.mon < 0 || tm.year < 0
 	|| tm.hour < 0 || tm.min < 0