aboutsummaryrefslogtreecommitdiff
path: root/rune.c
diff options
context:
space:
mode:
Diffstat (limited to 'rune.c')
-rw-r--r--rune.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/rune.c b/rune.c
index 65df3d3..92d9d2a 100644
--- a/rune.c
+++ b/rune.c
@@ -139,6 +139,8 @@ charntorune(Rune *rune, const char *str, int length)
l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
if (l <= Rune3)
goto bad;
+ if (l > Runemax)
+ goto bad;
*rune = l;
return 4;
}
@@ -222,6 +224,8 @@ chartorune(Rune *rune, const char *str)
l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
if (l <= Rune3)
goto bad;
+ if (l > Runemax)
+ goto bad;
*rune = l;
return 4;
}
@@ -313,7 +317,8 @@ runelen(Rune rune)
int
runenlen(const Rune *r, int nrune)
{
- int nb, c;
+ int nb;
+ ulong c; /* Rune is signed, so use unsigned for range check. */
nb = 0;
while(nrune--) {
@@ -324,8 +329,10 @@ runenlen(const Rune *r, int nrune)
nb += 2;
else if (c <= Rune3)
nb += 3;
- else /* assert(c <= Rune4) */
+ else if (c <= Runemax)
nb += 4;
+ else
+ nb += 3; /* Runeerror = 0xFFFD, see runetochar */
}
return nb;
}