diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-07-18 16:10:28 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-07-18 16:10:28 -0300 |
commit | ccb8b307f11c7497e61f617b12f3a7f0a697256c (patch) | |
tree | 91f6eb88650be03ab27433e2a3ee53f6d2dfcafd /lutf8lib.c | |
parent | 60b6599e8322dd93e3b33c9496ff035a1c45552f (diff) | |
download | lua-ccb8b307f11c7497e61f617b12f3a7f0a697256c.tar.gz lua-ccb8b307f11c7497e61f617b12f3a7f0a697256c.tar.bz2 lua-ccb8b307f11c7497e61f617b12f3a7f0a697256c.zip |
Correction in utf8.offset
Wrong utf-8 character may have no continuation bytes.
Diffstat (limited to 'lutf8lib.c')
-rw-r--r-- | lutf8lib.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -215,9 +215,10 @@ static int byteoffset (lua_State *L) { | |||
215 | } | 215 | } |
216 | lua_pushinteger(L, posi + 1); /* initial position */ | 216 | lua_pushinteger(L, posi + 1); /* initial position */ |
217 | if ((s[posi] & 0x80) != 0) { /* multi-byte character? */ | 217 | if ((s[posi] & 0x80) != 0) { /* multi-byte character? */ |
218 | do { | 218 | if (iscont(s[posi])) |
219 | posi++; | 219 | return luaL_error(L, "initial position is a continuation byte"); |
220 | } while (iscontp(s + posi + 1)); /* skip to final byte */ | 220 | while (iscontp(s + posi + 1)) |
221 | posi++; /* skip to last continuation byte */ | ||
221 | } | 222 | } |
222 | /* else one-byte character: final position is the initial one */ | 223 | /* else one-byte character: final position is the initial one */ |
223 | lua_pushinteger(L, posi + 1); /* 'posi' now is the final position */ | 224 | lua_pushinteger(L, posi + 1); /* 'posi' now is the final position */ |