From 400cf3c424bbca3ca560bef51c72a12a12e60e83 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Wed, 1 Nov 2023 10:13:21 +0100 Subject: [PATCH] xpath UPDATE use memstream instead of fixed buffer Fixes #2124 Signed-off-by: Toshikazu Nakayama --- src/xpath.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/xpath.c b/src/xpath.c index a80f1f96b..da1107d43 100644 --- a/src/xpath.c +++ b/src/xpath.c @@ -226,9 +226,10 @@ str2axis(const char *str, uint32_t str_len) static void print_expr_struct_debug(const struct lyxp_expr *exp) { -#define MSG_BUFFER_SIZE 128 - char tmp[MSG_BUFFER_SIZE]; + char *tmp; uint32_t i, j; + FILE *fp; + size_t s; if (!exp || (ly_ll < LY_LLDBG)) { return; @@ -236,18 +237,21 @@ print_expr_struct_debug(const struct lyxp_expr *exp) LOGDBG(LY_LDGXPATH, "expression \"%s\":", exp->expr); for (i = 0; i < exp->used; ++i) { - sprintf(tmp, "\ttoken %s, in expression \"%.*s\"", lyxp_token2str(exp->tokens[i]), exp->tok_len[i], + fp = open_memstream(&tmp, &s); + fprintf(fp, "\ttoken %s, in expression \"%.*s\"", lyxp_token2str(exp->tokens[i]), exp->tok_len[i], &exp->expr[exp->tok_pos[i]]); if (exp->repeat && exp->repeat[i]) { - sprintf(tmp + strlen(tmp), " (repeat %d", exp->repeat[i][0]); + fprintf(fp, " (repeat %d", exp->repeat[i][0]); for (j = 1; exp->repeat[i][j]; ++j) { - sprintf(tmp + strlen(tmp), ", %d", exp->repeat[i][j]); + fprintf(fp, ", %d", exp->repeat[i][j]); } - strcat(tmp, ")"); + fprintf(fp, ")"); } + fflush(fp); LOGDBG(LY_LDGXPATH, tmp); + fclose(fp); + free(tmp); } -#undef MSG_BUFFER_SIZE } #ifndef NDEBUG