shithub: riscv

Download patch

ref: 50e2c9b4d47c8a14f9b921d716f2cd070a4aabcd
parent: 5b5eb3b4b4a7e10e16dcbe7f287771c7e6e85aa8
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Apr 1 02:04:00 EDT 2014

sam, acme: fix character classes quoting for 21-bit runes

quote handling was broken with 21-bit runes. nextrec()
returned quoted rune as long rune | (Runemax+1) to escape
it.

with 16-bit runes, storing that long into 16-bit Rune
would automatically remove the escaping, but with 21-bit
runes, Rune is uint32 so the escaping would remain. we
now use (Runemask+1) instead, and mask the escaping off
explicitely when storing back to Rune.

--- a/sys/src/cmd/acme/regx.c
+++ b/sys/src/cmd/acme/regx.c
@@ -455,7 +455,7 @@
 			exprp++;
 			return '\n';
 		}
-		return *exprp++|(Runemax+1);
+		return *exprp++|(Runemask+1);
 	}
 	return *exprp++;
 }
@@ -491,11 +491,11 @@
 			if((c2 = nextrec()) == ']')
 				goto Error;
 			classp[n+0] = Runemax;
-			classp[n+1] = c1;
-			classp[n+2] = c2;
+			classp[n+1] = c1 & Runemask;
+			classp[n+2] = c2 & Runemask;
 			n += 3;
 		}else
-			classp[n++] = c1;
+			classp[n++] = c1 & Runemask;
 	}
 	classp[n] = 0;
 	if(nclass == Nclass){
--- a/sys/src/cmd/sam/regexp.c
+++ b/sys/src/cmd/sam/regexp.c
@@ -462,7 +462,7 @@
 			exprp++;
 			return '\n';
 		}
-		return *exprp++|(Runemax+1);
+		return *exprp++|(Runemask+1);
 	}
 	return *exprp++;
 }
@@ -498,11 +498,11 @@
 			if((c2 = nextrec()) == ']')
 				goto Error;
 			classp[n+0] = Runemax;
-			classp[n+1] = c1;
-			classp[n+2] = c2;
+			classp[n+1] = c1 & Runemask;
+			classp[n+2] = c2 & Runemask;
 			n += 3;
 		}else
-			classp[n++] = c1;
+			classp[n++] = c1 & Runemask;
 	}
 	classp[n] = 0;
 	if(nclass == Nclass){