From ae0a7453a0d34265df8de13a078ffd8274724080 Mon Sep 17 00:00:00 2001 From: Cai-Yao <729673078@qq.com> Date: Fri, 1 Nov 2024 05:14:07 +0000 Subject: [PATCH] fix show trace json exec error --- deps/oblib/src/lib/trace/ob_trace.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deps/oblib/src/lib/trace/ob_trace.cpp b/deps/oblib/src/lib/trace/ob_trace.cpp index d4789fd09..9a7396afb 100644 --- a/deps/oblib/src/lib/trace/ob_trace.cpp +++ b/deps/oblib/src/lib/trace/ob_trace.cpp @@ -261,7 +261,11 @@ int to_string_and_strip(const char* str, const int64_t length, char* buf, const } } } - if (OB_FAIL(ret) || pos + 2 >= buf_len) { + if (OB_FAIL(ret) || pos + 3 >= buf_len) { + // When the length of the tag exceeds buf_len, need ensure that the json format is legal when truncating. + // Pos in buf_len - 2 will fill ']' later. + buf[buf_len - 4] = '\"'; + buf[buf_len - 3] = '}'; buf[buf_len - 1] = 0; } else { buf[pos++] = '\"';