shithub: drawterm

Download patch

ref: b2e55f09f7dab23b49b186d90d89463696945505
parent: d6760dceedda73e9c86fd9e2a749abfb7c465099
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun May 7 12:14:35 EDT 2017

kernel: fix namelenerror(), avoid memrchr() and make it static (from 9front)

make sure the loop terminates and doesnt get stuck at
name == aname. avoid memrchr() as it conflicts with
libc on unix (drawterm). declare namelenerror() as
static.

--- a/kern/chan.c	Sat Apr 29 15:35:02 2017
+++ b/kern/chan.c	Sun May  7 12:14:35 2017
@@ -1089,19 +1089,7 @@
 	}
 }
 
-void*
-memrchr(void *va, int c, long n)
-{
-	uchar *a, *e;
-
-	a = va;
-	for(e=a+n-1; e>a; e--)
-		if(*e == c)
-			return e;
-	return nil;
-}
-
-void
+static void
 namelenerror(char *aname, int len, char *err)
 {
 	char *ename, *name, *next;
@@ -1122,9 +1110,11 @@
 		next = ename;
 		do{
 			name = next;
-			next = memrchr(aname, '/', name-aname);
-			if(next == nil)
-				next = aname;
+			if(next == aname)
+				break;
+			while(next > aname)
+				if(*--next == '/')
+					break;
 			len = ename-next;
 		}while(len < ERRMAX/3 || len + errlen < 2*ERRMAX/3);