mirror of
https://github.com/lua/lua
synced 2024-11-28 07:33:08 +03:00
In 'luaO_pushvfstring', all options use 'addstr2buff'
This commit is contained in:
parent
45a8f1b593
commit
00e34375ec
20
lobject.c
20
lobject.c
@ -529,9 +529,6 @@ static char *getbuff (BuffFS *buff, unsigned sz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define addsize(b,sz) ((b)->blen += (sz))
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Add 'str' to the buffer. If string is larger than the buffer space,
|
** Add 'str' to the buffer. If string is larger than the buffer space,
|
||||||
** push the string directly to the stack.
|
** push the string directly to the stack.
|
||||||
@ -540,7 +537,7 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) {
|
|||||||
if (slen <= BUFVFS) { /* does string fit into buffer? */
|
if (slen <= BUFVFS) { /* does string fit into buffer? */
|
||||||
char *bf = getbuff(buff, cast_uint(slen));
|
char *bf = getbuff(buff, cast_uint(slen));
|
||||||
memcpy(bf, str, slen); /* add string to buffer */
|
memcpy(bf, str, slen); /* add string to buffer */
|
||||||
addsize(buff, cast_uint(slen));
|
buff->blen += cast_uint(slen);
|
||||||
}
|
}
|
||||||
else { /* string larger than buffer */
|
else { /* string larger than buffer */
|
||||||
clearbuff(buff); /* string comes after buffer's content */
|
clearbuff(buff); /* string comes after buffer's content */
|
||||||
@ -553,9 +550,9 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) {
|
|||||||
** Add a numeral to the buffer.
|
** Add a numeral to the buffer.
|
||||||
*/
|
*/
|
||||||
static void addnum2buff (BuffFS *buff, TValue *num) {
|
static void addnum2buff (BuffFS *buff, TValue *num) {
|
||||||
char *numbuff = getbuff(buff, MAXNUMBER2STR);
|
char numbuff[MAXNUMBER2STR];
|
||||||
unsigned len = tostringbuff(num, numbuff); /* format number into 'numbuff' */
|
unsigned len = tostringbuff(num, numbuff); /* format number into 'numbuff' */
|
||||||
addsize(buff, len);
|
addstr2buff(buff, numbuff, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -601,11 +598,10 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'p': { /* a pointer */
|
case 'p': { /* a pointer */
|
||||||
const unsigned sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */
|
char bf[MAXNUMBER2STR]; /* enough space for '%p' */
|
||||||
char *bf = getbuff(&buff, sz);
|
|
||||||
void *p = va_arg(argp, void *);
|
void *p = va_arg(argp, void *);
|
||||||
int len = lua_pointer2str(bf, sz, p);
|
int len = lua_pointer2str(bf, MAXNUMBER2STR, p);
|
||||||
addsize(&buff, cast_uint(len));
|
addstr2buff(&buff, bf, cast_uint(len));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'U': { /* an 'unsigned long' as a UTF-8 sequence */
|
case 'U': { /* an 'unsigned long' as a UTF-8 sequence */
|
||||||
@ -619,8 +615,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
luaG_runerror(L, "invalid option '%%%c' to 'lua_pushfstring'",
|
addstr2buff(&buff, e, 2); /* keep unknown format in the result */
|
||||||
*(e + 1));
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt = e + 2; /* skip '%' and the specifier */
|
fmt = e + 2; /* skip '%' and the specifier */
|
||||||
|
Loading…
Reference in New Issue
Block a user