summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-05-27 11:46:47 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-05-27 11:46:47 -0300
commitaa8d4a782d88738b3ea921cde5a450656da8fa63 (patch)
treeecdc874d2476a40ad3857d2c03aaced9d0e04598
parentefcf24be0c22cba57b298161bf4ab0561fd3c08e (diff)
downloadlua-aa8d4a782d88738b3ea921cde5a450656da8fa63.tar.gz
lua-aa8d4a782d88738b3ea921cde5a450656da8fa63.tar.bz2
lua-aa8d4a782d88738b3ea921cde5a450656da8fa63.zip
Details (more uniformity in error messages)
-rw-r--r--lauxlib.c2
-rw-r--r--lutf8lib.c10
-rw-r--r--testes/utf8.lua18
3 files changed, 15 insertions, 15 deletions
diff --git a/lauxlib.c b/lauxlib.c
index f2ba704f..e6d74168 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -476,7 +476,7 @@ static void *resizebox (lua_State *L, int idx, size_t newsize) {
476 UBox *box = (UBox *)lua_touserdata(L, idx); 476 UBox *box = (UBox *)lua_touserdata(L, idx);
477 void *temp = allocf(ud, box->box, box->bsize, newsize); 477 void *temp = allocf(ud, box->box, box->bsize, newsize);
478 if (temp == NULL && newsize > 0) /* allocation error? */ 478 if (temp == NULL && newsize > 0) /* allocation error? */
479 luaL_error(L, "not enough memory for buffer allocation"); 479 luaL_error(L, "not enough memory");
480 box->box = temp; 480 box->box = temp;
481 box->bsize = newsize; 481 box->bsize = newsize;
482 return temp; 482 return temp;
diff --git a/lutf8lib.c b/lutf8lib.c
index 3b36a60e..901d985f 100644
--- a/lutf8lib.c
+++ b/lutf8lib.c
@@ -97,9 +97,9 @@ static int utflen (lua_State *L) {
97 lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len); 97 lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);
98 int lax = lua_toboolean(L, 4); 98 int lax = lua_toboolean(L, 4);
99 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2, 99 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,
100 "initial position out of string"); 100 "initial position out of bounds");
101 luaL_argcheck(L, --posj < (lua_Integer)len, 3, 101 luaL_argcheck(L, --posj < (lua_Integer)len, 3,
102 "final position out of string"); 102 "final position out of bounds");
103 while (posi <= posj) { 103 while (posi <= posj) {
104 const char *s1 = utf8_decode(s + posi, NULL, !lax); 104 const char *s1 = utf8_decode(s + posi, NULL, !lax);
105 if (s1 == NULL) { /* conversion error? */ 105 if (s1 == NULL) { /* conversion error? */
@@ -127,8 +127,8 @@ static int codepoint (lua_State *L) {
127 int lax = lua_toboolean(L, 4); 127 int lax = lua_toboolean(L, 4);
128 int n; 128 int n;
129 const char *se; 129 const char *se;
130 luaL_argcheck(L, posi >= 1, 2, "out of range"); 130 luaL_argcheck(L, posi >= 1, 2, "out of bounds");
131 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range"); 131 luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of bounds");
132 if (posi > pose) return 0; /* empty interval; return no values */ 132 if (posi > pose) return 0; /* empty interval; return no values */
133 if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */ 133 if (pose - posi >= INT_MAX) /* (lua_Integer -> int) overflow? */
134 return luaL_error(L, "string slice too long"); 134 return luaL_error(L, "string slice too long");
@@ -187,7 +187,7 @@ static int byteoffset (lua_State *L) {
187 lua_Integer posi = (n >= 0) ? 1 : len + 1; 187 lua_Integer posi = (n >= 0) ? 1 : len + 1;
188 posi = u_posrelat(luaL_optinteger(L, 3, posi), len); 188 posi = u_posrelat(luaL_optinteger(L, 3, posi), len);
189 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, 189 luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,
190 "position out of range"); 190 "position out of bounds");
191 if (n == 0) { 191 if (n == 0) {
192 /* find beginning of current byte sequence */ 192 /* find beginning of current byte sequence */
193 while (posi > 0 && iscont(s + posi)) posi--; 193 while (posi > 0 && iscont(s + posi)) posi--;
diff --git a/testes/utf8.lua b/testes/utf8.lua
index 5954f6e8..6010d1ad 100644
--- a/testes/utf8.lua
+++ b/testes/utf8.lua
@@ -115,17 +115,17 @@ do
115end 115end
116 116
117-- error in initial position for offset 117-- error in initial position for offset
118checkerror("position out of range", utf8.offset, "abc", 1, 5) 118checkerror("position out of bounds", utf8.offset, "abc", 1, 5)
119checkerror("position out of range", utf8.offset, "abc", 1, -4) 119checkerror("position out of bounds", utf8.offset, "abc", 1, -4)
120checkerror("position out of range", utf8.offset, "", 1, 2) 120checkerror("position out of bounds", utf8.offset, "", 1, 2)
121checkerror("position out of range", utf8.offset, "", 1, -1) 121checkerror("position out of bounds", utf8.offset, "", 1, -1)
122checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) 122checkerror("continuation byte", utf8.offset, "𦧺", 1, 2)
123checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) 123checkerror("continuation byte", utf8.offset, "𦧺", 1, 2)
124checkerror("continuation byte", utf8.offset, "\x80", 1) 124checkerror("continuation byte", utf8.offset, "\x80", 1)
125 125
126-- error in indices for len 126-- error in indices for len
127checkerror("out of string", utf8.len, "abc", 0, 2) 127checkerror("out of bounds", utf8.len, "abc", 0, 2)
128checkerror("out of string", utf8.len, "abc", 1, 4) 128checkerror("out of bounds", utf8.len, "abc", 1, 4)
129 129
130 130
131local s = "hello World" 131local s = "hello World"
@@ -140,11 +140,11 @@ do
140 local t = {utf8.codepoint(s,1,#s - 1)} 140 local t = {utf8.codepoint(s,1,#s - 1)}
141 assert(#t == 3 and t[1] == 225 and t[2] == 233 and t[3] == 237) 141 assert(#t == 3 and t[1] == 225 and t[2] == 233 and t[3] == 237)
142 checkerror("invalid UTF%-8 code", utf8.codepoint, s, 1, #s) 142 checkerror("invalid UTF%-8 code", utf8.codepoint, s, 1, #s)
143 checkerror("out of range", utf8.codepoint, s, #s + 1) 143 checkerror("out of bounds", utf8.codepoint, s, #s + 1)
144 t = {utf8.codepoint(s, 4, 3)} 144 t = {utf8.codepoint(s, 4, 3)}
145 assert(#t == 0) 145 assert(#t == 0)
146 checkerror("out of range", utf8.codepoint, s, -(#s + 1), 1) 146 checkerror("out of bounds", utf8.codepoint, s, -(#s + 1), 1)
147 checkerror("out of range", utf8.codepoint, s, 1, #s + 1) 147 checkerror("out of bounds", utf8.codepoint, s, 1, #s + 1)
148 -- surrogates 148 -- surrogates
149 assert(utf8.codepoint("\u{D7FF}") == 0xD800 - 1) 149 assert(utf8.codepoint("\u{D7FF}") == 0xD800 - 1)
150 assert(utf8.codepoint("\u{E000}") == 0xDFFF + 1) 150 assert(utf8.codepoint("\u{E000}") == 0xDFFF + 1)