Use snprintf in client/deps

This commit is contained in:
Doridian 2022-06-10 12:29:18 -07:00
commit fe4599fb14
7 changed files with 35 additions and 35 deletions

View file

@ -215,7 +215,7 @@ const char *luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp) {
}
case 'p': {
char buff[4 * sizeof(void *) + 8]; /* should be enough space for a `%p' */
int l = sprintf(buff, "%p", va_arg(argp, void *));
int l = snprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
pushstr(L, buff, l);
break;
}

View file

@ -879,9 +879,9 @@ static void addquoted(lua_State *L, luaL_Buffer *b, int arg) {
} else if (*s == '\0' || iscntrl(uchar(*s))) {
char buff[10];
if (!isdigit(uchar(*(s + 1))))
sprintf(buff, "\\%d", (int)uchar(*s));
snprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s));
else
sprintf(buff, "\\%03d", (int)uchar(*s));
snprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s));
luaL_addstring(b, buff);
} else
luaL_addchar(b, *s);
@ -947,7 +947,7 @@ static int str_format(lua_State *L) {
strfrmt = scanformat(L, strfrmt, form);
switch (*strfrmt++) {
case 'c': {
nb = sprintf(buff, form, luaL_checkint(L, arg));
nb = snprintf(buff, MAX_ITEM, form, luaL_checkint(L, arg));
break;
}
case 'd':
@ -958,7 +958,7 @@ static int str_format(lua_State *L) {
luaL_argcheck(L, -1 < diff && diff < 1, arg,
"not a number in proper range");
addlenmod(form, LUA_INTFRMLEN);
nb = sprintf(buff, form, ni);
nb = snprintf(buff, MAX_ITEM, form, ni);
break;
}
case 'o':
@ -971,7 +971,7 @@ static int str_format(lua_State *L) {
luaL_argcheck(L, -1 < diff && diff < 1, arg,
"not a non-negative number in proper range");
addlenmod(form, LUA_INTFRMLEN);
nb = sprintf(buff, form, ni);
nb = snprintf(buff, MAX_ITEM, form, ni);
break;
}
case 'e':
@ -984,7 +984,7 @@ static int str_format(lua_State *L) {
case 'g':
case 'G': {
addlenmod(form, LUA_FLTFRMLEN);
nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
nb = snprintf(buff, MAX_ITEM, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'q': {
@ -1000,7 +1000,7 @@ static int str_format(lua_State *L) {
luaL_addvalue(&b);
break;
} else {
nb = sprintf(buff, form, s);
nb = snprintf(buff, MAX_ITEM, form, s);
lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
break;
}

View file

@ -408,7 +408,7 @@
*/
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define lua_number2str(s,l,n) snprintf((s), (l), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */

View file

@ -49,7 +49,7 @@ int luaV_tostring(lua_State *L, StkId obj) {
else {
char s[LUAI_MAXNUMBER2STR];
lua_Number n = nvalue(obj);
int l = lua_number2str(s, n);
int l = lua_number2str(s, sizeof(s), n);
setsvalue2s(L, obj, luaS_newlstr(L, s, l));
return 1;
}