aboutsummaryrefslogtreecommitdiff
path: root/lutf8lib.c
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2016-01-22 15:58:48 +0100
committerPhilipp Janda <siffiejoe@gmx.net>2016-01-22 15:58:48 +0100
commitca85188590e677edcc9290d29e69a3692187c826 (patch)
tree6223894654ff62468f1086423caf31f459e7861b /lutf8lib.c
parentabf4ea9645ce3ff0c390a57ab3e3e4f82d9a4035 (diff)
downloadlua-compat-5.3-ca85188590e677edcc9290d29e69a3692187c826.tar.gz
lua-compat-5.3-ca85188590e677edcc9290d29e69a3692187c826.tar.bz2
lua-compat-5.3-ca85188590e677edcc9290d29e69a3692187c826.zip
Update backports.
The backports of lstrlib.c, ltablib.c, and lutf8lib.c have been updated to Lua version 5.3.2.
Diffstat (limited to 'lutf8lib.c')
-rw-r--r--lutf8lib.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/lutf8lib.c b/lutf8lib.c
index be4f087..9042582 100644
--- a/lutf8lib.c
+++ b/lutf8lib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lutf8lib.c,v 1.13 2014/11/02 19:19:04 roberto Exp $ 2** $Id: lutf8lib.c,v 1.15 2015/03/28 19:16:55 roberto Exp $
3** Standard library for UTF-8 manipulation 3** Standard library for UTF-8 manipulation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,6 +11,7 @@
11 11
12 12
13#include <assert.h> 13#include <assert.h>
14#include <limits.h>
14#include <stdlib.h> 15#include <stdlib.h>
15#include <string.h> 16#include <string.h>
16 17
@@ -37,7 +38,7 @@ static lua_Integer u_posrelat (lua_Integer pos, size_t len) {
37** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid. 38** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.
38*/ 39*/
39static const char *utf8_decode (const char *o, int *val) { 40static const char *utf8_decode (const char *o, int *val) {
40 static unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF}; 41 static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};
41 const unsigned char *s = (const unsigned char *)o; 42 const unsigned char *s = (const unsigned char *)o;
42 unsigned int c = s[0]; 43 unsigned int c = s[0];
43 unsigned int res = 0; /* final result */ 44 unsigned int res = 0; /* final result */
@@ -106,9 +107,9 @@ static int codepoint (lua_State *L) {
106 luaL_argcheck(L, posi >= 1, 2, "out of range"); 107 luaL_argcheck(L, posi >= 1, 2, "out of range");
107 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range"); 108 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range");
108 if (posi > pose) return 0; /* empty interval; return no values */ 109 if (posi > pose) return 0; /* empty interval; return no values */
109 n = (int)(pose - posi + 1); 110 if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */
110 if (posi + n <= pose) /* (lua_Integer -> int) overflow? */
111 return luaL_error(L, "string slice too long"); 111 return luaL_error(L, "string slice too long");
112 n = (int)(pose - posi) + 1;
112 luaL_checkstack(L, n, "string slice too long"); 113 luaL_checkstack(L, n, "string slice too long");
113 n = 0; 114 n = 0;
114 se = s + pose; 115 se = s + pose;
@@ -234,7 +235,7 @@ static int iter_codes (lua_State *L) {
234#define UTF8PATT "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" 235#define UTF8PATT "[\0-\x7F\xC2-\xF4][\x80-\xBF]*"
235 236
236 237
237static struct luaL_Reg funcs[] = { 238static const luaL_Reg funcs[] = {
238 {"offset", byteoffset}, 239 {"offset", byteoffset},
239 {"codepoint", codepoint}, 240 {"codepoint", codepoint},
240 {"char", utfchar}, 241 {"char", utfchar},
@@ -248,7 +249,7 @@ static struct luaL_Reg funcs[] = {
248 249
249LUAMOD_API int luaopen_utf8 (lua_State *L) { 250LUAMOD_API int luaopen_utf8 (lua_State *L) {
250 luaL_newlib(L, funcs); 251 luaL_newlib(L, funcs);
251 lua_pushliteral(L, UTF8PATT); 252 lua_pushlstring(L, UTF8PATT, sizeof(UTF8PATT)/sizeof(char) - 1);
252 lua_setfield(L, -2, "charpattern"); 253 lua_setfield(L, -2, "charpattern");
253 return 1; 254 return 1;
254} 255}