diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-09-20 10:06:06 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-09-20 10:06:06 -0300 |
commit | 00e34375ec7996422a617b0e99024d42ba61f634 (patch) | |
tree | 5872e7f056ea21be316edf7512bd255aba9b6639 | |
parent | 45a8f1b59310f9db74d9fc17264be2c2b2a06217 (diff) | |
download | lua-00e34375ec7996422a617b0e99024d42ba61f634.tar.gz lua-00e34375ec7996422a617b0e99024d42ba61f634.tar.bz2 lua-00e34375ec7996422a617b0e99024d42ba61f634.zip |
In 'luaO_pushvfstring', all options use 'addstr2buff'
-rw-r--r-- | lobject.c | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -529,9 +529,6 @@ static char *getbuff (BuffFS *buff, unsigned sz) { | |||
529 | } | 529 | } |
530 | 530 | ||
531 | 531 | ||
532 | #define addsize(b,sz) ((b)->blen += (sz)) | ||
533 | |||
534 | |||
535 | /* | 532 | /* |
536 | ** Add 'str' to the buffer. If string is larger than the buffer space, | 533 | ** Add 'str' to the buffer. If string is larger than the buffer space, |
537 | ** push the string directly to the stack. | 534 | ** push the string directly to the stack. |
@@ -540,7 +537,7 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { | |||
540 | if (slen <= BUFVFS) { /* does string fit into buffer? */ | 537 | if (slen <= BUFVFS) { /* does string fit into buffer? */ |
541 | char *bf = getbuff(buff, cast_uint(slen)); | 538 | char *bf = getbuff(buff, cast_uint(slen)); |
542 | memcpy(bf, str, slen); /* add string to buffer */ | 539 | memcpy(bf, str, slen); /* add string to buffer */ |
543 | addsize(buff, cast_uint(slen)); | 540 | buff->blen += cast_uint(slen); |
544 | } | 541 | } |
545 | else { /* string larger than buffer */ | 542 | else { /* string larger than buffer */ |
546 | clearbuff(buff); /* string comes after buffer's content */ | 543 | clearbuff(buff); /* string comes after buffer's content */ |
@@ -553,9 +550,9 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) { | |||
553 | ** Add a numeral to the buffer. | 550 | ** Add a numeral to the buffer. |
554 | */ | 551 | */ |
555 | static void addnum2buff (BuffFS *buff, TValue *num) { | 552 | static void addnum2buff (BuffFS *buff, TValue *num) { |
556 | char *numbuff = getbuff(buff, MAXNUMBER2STR); | 553 | char numbuff[MAXNUMBER2STR]; |
557 | unsigned len = tostringbuff(num, numbuff); /* format number into 'numbuff' */ | 554 | unsigned len = tostringbuff(num, numbuff); /* format number into 'numbuff' */ |
558 | addsize(buff, len); | 555 | addstr2buff(buff, numbuff, len); |
559 | } | 556 | } |
560 | 557 | ||
561 | 558 | ||
@@ -601,11 +598,10 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
601 | break; | 598 | break; |
602 | } | 599 | } |
603 | case 'p': { /* a pointer */ | 600 | case 'p': { /* a pointer */ |
604 | const unsigned sz = 3 * sizeof(void*) + 8; /* enough space for '%p' */ | 601 | char bf[MAXNUMBER2STR]; /* enough space for '%p' */ |
605 | char *bf = getbuff(&buff, sz); | ||
606 | void *p = va_arg(argp, void *); | 602 | void *p = va_arg(argp, void *); |
607 | int len = lua_pointer2str(bf, sz, p); | 603 | int len = lua_pointer2str(bf, MAXNUMBER2STR, p); |
608 | addsize(&buff, cast_uint(len)); | 604 | addstr2buff(&buff, bf, cast_uint(len)); |
609 | break; | 605 | break; |
610 | } | 606 | } |
611 | case 'U': { /* an 'unsigned long' as a UTF-8 sequence */ | 607 | 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) { | |||
619 | break; | 615 | break; |
620 | } | 616 | } |
621 | default: { | 617 | default: { |
622 | luaG_runerror(L, "invalid option '%%%c' to 'lua_pushfstring'", | 618 | addstr2buff(&buff, e, 2); /* keep unknown format in the result */ |
623 | *(e + 1)); | 619 | break; |
624 | } | 620 | } |
625 | } | 621 | } |
626 | fmt = e + 2; /* skip '%' and the specifier */ | 622 | fmt = e + 2; /* skip '%' and the specifier */ |