Hi,
More new assorted suggestions for the Lua.
10. Avoid calling strlen at lua_addstring, when adding a constant literal string.
diff --git a/lauxlib.c b/lauxlib.c
index 73504389..e28872cd 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -139,7 +139,7 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,
luaL_addstring(&b, msg);
luaL_addchar(&b, '\n');
}
- luaL_addstring(&b, "stack traceback:");
+ luaL_addlstring(&b, "stack traceback:", sizeof("stack traceback:") - 1);
Typo.
14.
Avoid calling strlen at lua_addstring, when the size of is known.
diff --git a/lstrlib.c b/lstrlib.c
index 940a14ca..8ab967d2 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1106,12 +1106,13 @@ static void addquoted (luaL_Buffer *b, const char *s, size_t len) {
luaL_addchar(b, *s);
}
else if (iscntrl(uchar(*s))) {
- char buff[10];
+ char buff[12];
+ size_t l;
if (!isdigit(uchar(*(s+1))))
- l_sprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s));
+ l = l_sprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s));
else
- l_sprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s));
- luaL_addstring(b, buff);
+ l = l_sprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s));
+ luaL_addlstring(b, buff, l);
}
else
luaL_addchar(b, *s);
regards,
Ranier Vilela