Browse Source

Details (more uniformity in error messages)

Roberto Ierusalimschy 5 years ago
parent
commit
aa8d4a782d
3 changed files with 15 additions and 15 deletions
  1. 1 1
      lauxlib.c
  2. 5 5
      lutf8lib.c
  3. 9 9
      testes/utf8.lua

+ 1 - 1
lauxlib.c

@@ -476,7 +476,7 @@ static void *resizebox (lua_State *L, int idx, size_t newsize) {
   UBox *box = (UBox *)lua_touserdata(L, idx);
   UBox *box = (UBox *)lua_touserdata(L, idx);
   void *temp = allocf(ud, box->box, box->bsize, newsize);
   void *temp = allocf(ud, box->box, box->bsize, newsize);
   if (temp == NULL && newsize > 0)  /* allocation error? */
   if (temp == NULL && newsize > 0)  /* allocation error? */
-    luaL_error(L, "not enough memory for buffer allocation");
+    luaL_error(L, "not enough memory");
   box->box = temp;
   box->box = temp;
   box->bsize = newsize;
   box->bsize = newsize;
   return temp;
   return temp;

+ 5 - 5
lutf8lib.c

@@ -97,9 +97,9 @@ static int utflen (lua_State *L) {
   lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);
   lua_Integer posj = u_posrelat(luaL_optinteger(L, 3, -1), len);
   int lax = lua_toboolean(L, 4);
   int lax = lua_toboolean(L, 4);
   luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,
   luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 2,
-                   "initial position out of string");
+                   "initial position out of bounds");
   luaL_argcheck(L, --posj < (lua_Integer)len, 3,
   luaL_argcheck(L, --posj < (lua_Integer)len, 3,
-                   "final position out of string");
+                   "final position out of bounds");
   while (posi <= posj) {
   while (posi <= posj) {
     const char *s1 = utf8_decode(s + posi, NULL, !lax);
     const char *s1 = utf8_decode(s + posi, NULL, !lax);
     if (s1 == NULL) {  /* conversion error? */
     if (s1 == NULL) {  /* conversion error? */
@@ -127,8 +127,8 @@ static int codepoint (lua_State *L) {
   int lax = lua_toboolean(L, 4);
   int lax = lua_toboolean(L, 4);
   int n;
   int n;
   const char *se;
   const char *se;
-  luaL_argcheck(L, posi >= 1, 2, "out of range");
-  luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range");
+  luaL_argcheck(L, posi >= 1, 2, "out of bounds");
+  luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of bounds");
   if (posi > pose) return 0;  /* empty interval; return no values */
   if (posi > pose) return 0;  /* empty interval; return no values */
   if (pose - posi >= INT_MAX)  /* (lua_Integer -> int) overflow? */
   if (pose - posi >= INT_MAX)  /* (lua_Integer -> int) overflow? */
     return luaL_error(L, "string slice too long");
     return luaL_error(L, "string slice too long");
@@ -187,7 +187,7 @@ static int byteoffset (lua_State *L) {
   lua_Integer posi = (n >= 0) ? 1 : len + 1;
   lua_Integer posi = (n >= 0) ? 1 : len + 1;
   posi = u_posrelat(luaL_optinteger(L, 3, posi), len);
   posi = u_posrelat(luaL_optinteger(L, 3, posi), len);
   luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,
   luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,
-                   "position out of range");
+                   "position out of bounds");
   if (n == 0) {
   if (n == 0) {
     /* find beginning of current byte sequence */
     /* find beginning of current byte sequence */
     while (posi > 0 && iscont(s + posi)) posi--;
     while (posi > 0 && iscont(s + posi)) posi--;

+ 9 - 9
testes/utf8.lua

@@ -115,17 +115,17 @@ do
 end
 end
 
 
 -- error in initial position for offset
 -- error in initial position for offset
-checkerror("position out of range", utf8.offset, "abc", 1, 5)
-checkerror("position out of range", utf8.offset, "abc", 1, -4)
-checkerror("position out of range", utf8.offset, "", 1, 2)
-checkerror("position out of range", utf8.offset, "", 1, -1)
+checkerror("position out of bounds", utf8.offset, "abc", 1, 5)
+checkerror("position out of bounds", utf8.offset, "abc", 1, -4)
+checkerror("position out of bounds", utf8.offset, "", 1, 2)
+checkerror("position out of bounds", utf8.offset, "", 1, -1)
 checkerror("continuation byte", utf8.offset, "𦧺", 1, 2)
 checkerror("continuation byte", utf8.offset, "𦧺", 1, 2)
 checkerror("continuation byte", utf8.offset, "𦧺", 1, 2)
 checkerror("continuation byte", utf8.offset, "𦧺", 1, 2)
 checkerror("continuation byte", utf8.offset, "\x80", 1)
 checkerror("continuation byte", utf8.offset, "\x80", 1)
 
 
 -- error in indices for len
 -- error in indices for len
-checkerror("out of string", utf8.len, "abc", 0, 2)
-checkerror("out of string", utf8.len, "abc", 1, 4)
+checkerror("out of bounds", utf8.len, "abc", 0, 2)
+checkerror("out of bounds", utf8.len, "abc", 1, 4)
 
 
 
 
 local s = "hello World"
 local s = "hello World"
@@ -140,11 +140,11 @@ do
   local t = {utf8.codepoint(s,1,#s - 1)}
   local t = {utf8.codepoint(s,1,#s - 1)}
   assert(#t == 3 and t[1] == 225 and t[2] == 233 and t[3] == 237)
   assert(#t == 3 and t[1] == 225 and t[2] == 233 and t[3] == 237)
   checkerror("invalid UTF%-8 code", utf8.codepoint, s, 1, #s)
   checkerror("invalid UTF%-8 code", utf8.codepoint, s, 1, #s)
-  checkerror("out of range", utf8.codepoint, s, #s + 1)
+  checkerror("out of bounds", utf8.codepoint, s, #s + 1)
   t = {utf8.codepoint(s, 4, 3)}
   t = {utf8.codepoint(s, 4, 3)}
   assert(#t == 0)
   assert(#t == 0)
-  checkerror("out of range", utf8.codepoint, s, -(#s + 1), 1)
-  checkerror("out of range", utf8.codepoint, s, 1, #s + 1)
+  checkerror("out of bounds", utf8.codepoint, s, -(#s + 1), 1)
+  checkerror("out of bounds", utf8.codepoint, s, 1, #s + 1)
   -- surrogates
   -- surrogates
   assert(utf8.codepoint("\u{D7FF}") == 0xD800 - 1)
   assert(utf8.codepoint("\u{D7FF}") == 0xD800 - 1)
   assert(utf8.codepoint("\u{E000}") == 0xDFFF + 1)
   assert(utf8.codepoint("\u{E000}") == 0xDFFF + 1)