aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib_buffer.c1
-rw-r--r--src/lj_errmsg.h1
-rw-r--r--src/lj_strfmt.c5
3 files changed, 6 insertions, 1 deletions
diff --git a/src/lib_buffer.c b/src/lib_buffer.c
index f13320c4..cb7531a2 100644
--- a/src/lib_buffer.c
+++ b/src/lib_buffer.c
@@ -126,6 +126,7 @@ LJLIB_CF(buffer_method_put)
126 lj_strfmt_putfnum((SBuf *)sbx, STRFMT_G14, numV(o)); 126 lj_strfmt_putfnum((SBuf *)sbx, STRFMT_G14, numV(o));
127 } else if (tvisbuf(o)) { 127 } else if (tvisbuf(o)) {
128 SBufExt *sbx2 = bufV(o); 128 SBufExt *sbx2 = bufV(o);
129 if (sbx2 == sbx) lj_err_arg(L, arg+1, LJ_ERR_BUFFER_SELF);
129 lj_buf_putmem((SBuf *)sbx, sbx2->r, sbufxlen(sbx2)); 130 lj_buf_putmem((SBuf *)sbx, sbx2->r, sbufxlen(sbx2));
130 } else if (!mo && !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { 131 } else if (!mo && !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {
131 /* Call __tostring metamethod inline. */ 132 /* Call __tostring metamethod inline. */
diff --git a/src/lj_errmsg.h b/src/lj_errmsg.h
index 56be4bb9..89e67496 100644
--- a/src/lj_errmsg.h
+++ b/src/lj_errmsg.h
@@ -182,6 +182,7 @@ ERRDEF(FFI_NYICALL, "NYI: cannot call this C function (yet)")
182 182
183#if LJ_HASBUFFER 183#if LJ_HASBUFFER
184/* String buffer errors. */ 184/* String buffer errors. */
185ERRDEF(BUFFER_SELF, "cannot put buffer into itself")
185ERRDEF(BUFFER_BADOPT, "bad options table") 186ERRDEF(BUFFER_BADOPT, "bad options table")
186ERRDEF(BUFFER_BADENC, "cannot serialize " LUA_QS) 187ERRDEF(BUFFER_BADENC, "cannot serialize " LUA_QS)
187ERRDEF(BUFFER_BADDEC, "cannot deserialize tag 0x%02x") 188ERRDEF(BUFFER_BADDEC, "cannot deserialize tag 0x%02x")
diff --git a/src/lj_strfmt.c b/src/lj_strfmt.c
index 7b073470..945954aa 100644
--- a/src/lj_strfmt.c
+++ b/src/lj_strfmt.c
@@ -431,7 +431,7 @@ int lj_strfmt_putarg(lua_State *L, SBuf *sb, int arg, int retry)
431 MSize len; 431 MSize len;
432 const char *s; 432 const char *s;
433 cTValue *mo; 433 cTValue *mo;
434 if (LJ_UNLIKELY(!tvisstr(o)) && retry >= 0 && 434 if (LJ_UNLIKELY(!tvisstr(o) && !tvisbuf(o)) && retry >= 0 &&
435 !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) { 435 !tvisnil(mo = lj_meta_lookup(L, o, MM_tostring))) {
436 /* Call __tostring metamethod once. */ 436 /* Call __tostring metamethod once. */
437 copyTV(L, L->top++, mo); 437 copyTV(L, L->top++, mo);
@@ -447,10 +447,13 @@ int lj_strfmt_putarg(lua_State *L, SBuf *sb, int arg, int retry)
447 if (LJ_LIKELY(tvisstr(o))) { 447 if (LJ_LIKELY(tvisstr(o))) {
448 len = strV(o)->len; 448 len = strV(o)->len;
449 s = strVdata(o); 449 s = strVdata(o);
450#if LJ_HASBUFFER
450 } else if (tvisbuf(o)) { 451 } else if (tvisbuf(o)) {
451 SBufExt *sbx = bufV(o); 452 SBufExt *sbx = bufV(o);
453 if (sbx == (SBufExt *)sb) lj_err_arg(L, arg+1, LJ_ERR_BUFFER_SELF);
452 len = sbufxlen(sbx); 454 len = sbufxlen(sbx);
453 s = sbx->r; 455 s = sbx->r;
456#endif
454 } else { 457 } else {
455 GCstr *str = lj_strfmt_obj(L, o); 458 GCstr *str = lj_strfmt_obj(L, o);
456 len = str->len; 459 len = str->len;