diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-03-28 16:16:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-03-28 16:16:55 -0300 |
commit | f2a813ae108a04e7de0478bd3c3ebf332268b043 (patch) | |
tree | c1875da768291bca64564e91cd98436298a3daa0 /lutf8lib.c | |
parent | e723c75c02a48d0c766f1f30f7a321f7fdb239dc (diff) | |
download | lua-f2a813ae108a04e7de0478bd3c3ebf332268b043.tar.gz lua-f2a813ae108a04e7de0478bd3c3ebf332268b043.tar.bz2 lua-f2a813ae108a04e7de0478bd3c3ebf332268b043.zip |
details (avoid some 'lint' warnings)
Diffstat (limited to 'lutf8lib.c')
-rw-r--r-- | lutf8lib.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lutf8lib.c,v 1.13 2014/11/02 19:19:04 roberto Exp roberto $ | 2 | ** $Id: lutf8lib.c,v 1.14 2015/03/05 16:07:46 roberto Exp roberto $ |
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 | */ |
39 | static const char *utf8_decode (const char *o, int *val) { | 40 | static 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 | ||
237 | static struct luaL_Reg funcs[] = { | 238 | static const luaL_Reg funcs[] = { |
238 | {"offset", byteoffset}, | 239 | {"offset", byteoffset}, |
239 | {"codepoint", codepoint}, | 240 | {"codepoint", codepoint}, |
240 | {"char", utfchar}, | 241 | {"char", utfchar}, |