shithub: front

Download patch

ref: 394e9c223572b14d766c25fd864c621d7015d1a8
parent: 4d484968bfe7b8478cbcc8f1784b15b3aab64d7b
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Oct 4 20:06:50 EDT 2024

libc/runeistype: accept out of range runes

out of range runes should just return 0 for whether
they're within any of the classes.

--- a/sys/man/2/isalpharune
+++ b/sys/man/2/isalpharune
@@ -47,6 +47,9 @@
 The names are self-explanatory.
 .PP
 The case-conversion routines return the character unchanged if it has no case.
+.PP
+If a rune contains a value that is not a valid codepoint (ie, values less than
+zero, or greater than Runemax), these routines return 0.
 .SH SOURCE
 .B /sys/src/libc/port/mkrunetype.c
 .br
--- a/sys/src/libc/port/runeistype.c
+++ b/sys/src/libc/port/runeistype.c
@@ -6,6 +6,8 @@
 int
 isspacerune(Rune c)
 {
+	if(c < 0 || c > Runemax)
+		return 0;
 	return (mergedlkup(c) & Lspace) == Lspace;
 }
 
@@ -12,6 +14,8 @@
 int
 isalpharune(Rune c)
 {
+	if(c < 0 || c > Runemax)
+		return 0;
 	return (mergedlkup(c) & Lalpha) == Lalpha;
 }
 
@@ -18,6 +22,8 @@
 int
 isdigitrune(Rune c)
 {
+	if(c < 0 || c > Runemax)
+		return 0;
 	return (mergedlkup(c) & Ldigit) == Ldigit;
 }
 
@@ -24,6 +30,8 @@
 int
 isupperrune(Rune c)
 {
+	if(c < 0 || c > Runemax)
+		return 0;
 	return (mergedlkup(c) & Lupper) == Lupper;
 }
 
@@ -30,6 +38,8 @@
 int
 islowerrune(Rune c)
 {
+	if(c < 0 || c > Runemax)
+		return 0;
 	return (mergedlkup(c) & Llower) == Llower;
 }
 
@@ -36,5 +46,7 @@
 int
 istitlerune(Rune c)
 {
+	if(c < 0 || c > Runemax)
+		return 0;
 	return (mergedlkup(c) & Ltitle) == Ltitle;
 }
--