kill sprintf

This commit is contained in:
christos 2014-03-26 22:03:26 +00:00
parent 968c5f53d8
commit c6b4d36c05
4 changed files with 16 additions and 16 deletions

View File

@ -1,7 +1,7 @@
/* $NetBSD: lobject.c,v 1.1.1.2 2012/03/15 00:08:09 alnsn Exp $ */
/* $NetBSD: lobject.c,v 1.2 2014/03/26 22:03:26 christos Exp $ */
/*
** $Id: lobject.c,v 1.1.1.2 2012/03/15 00:08:09 alnsn Exp $
** $Id: lobject.c,v 1.2 2014/03/26 22:03:26 christos Exp $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -144,7 +144,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' */
sprintf(buff, "%p", va_arg(argp, void *));
snprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
pushstr(L, buff);
break;
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: lstrlib.c,v 1.3 2013/12/16 23:25:56 lneto Exp $ */
/* $NetBSD: lstrlib.c,v 1.4 2014/03/26 22:03:26 christos Exp $ */
/*
** $Id: lstrlib.c,v 1.3 2013/12/16 23:25:56 lneto Exp $
** $Id: lstrlib.c,v 1.4 2014/03/26 22:03:26 christos Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@ -776,27 +776,27 @@ static int str_format (lua_State *L) {
strfrmt = scanformat(L, strfrmt, form);
switch (*strfrmt++) {
case 'c': {
sprintf(buff, form, (int)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (int)luaL_checknumber(L, arg));
break;
}
case 'd': case 'i': {
addintlen(form);
sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'o': case 'u': case 'x': case 'X': {
addintlen(form);
#ifndef _KERNEL
sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
#else
sprintf(buff, form, (LUA_UINTFRM_T)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (LUA_UINTFRM_T)luaL_checknumber(L, arg));
#endif
break;
}
#ifndef _KERNEL
case 'e': case 'E': case 'f':
case 'g': case 'G': {
sprintf(buff, form, (double)luaL_checknumber(L, arg));
snprintf(buff, sizeof(buff), form, (double)luaL_checknumber(L, arg));
break;
}
#endif
@ -815,7 +815,7 @@ static int str_format (lua_State *L) {
continue; /* skip the `addsize' at the end */
}
else {
sprintf(buff, form, s);
snprintf(buff, sizeof(buff), form, s);
break;
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: luaconf.h,v 1.6 2013/12/16 23:25:56 lneto Exp $ */
/* $NetBSD: luaconf.h,v 1.7 2014/03/26 22:03:26 christos Exp $ */
/*
** Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
@ -545,7 +545,7 @@
#define lua_str2number(s,p) strtod((s), (p))
#endif
#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

@ -1,7 +1,7 @@
/* $NetBSD: lvm.c,v 1.1.1.2 2012/03/15 00:08:05 alnsn Exp $ */
/* $NetBSD: lvm.c,v 1.2 2014/03/26 22:03:26 christos Exp $ */
/*
** $Id: lvm.c,v 1.1.1.2 2012/03/15 00:08:05 alnsn Exp $
** $Id: lvm.c,v 1.2 2014/03/26 22:03:26 christos Exp $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -52,7 +52,7 @@ int luaV_tostring (lua_State *L, StkId obj) {
else {
char s[LUAI_MAXNUMBER2STR];
lua_Number n = nvalue(obj);
lua_number2str(s, n);
lua_number2str(s, sizeof(s), n);
setsvalue2s(L, obj, luaS_new(L, s));
return 1;
}