xpath UPDATE use memstream instead of fixed buffer
Fixes #2124
Signed-off-by: Toshikazu Nakayama <toshikazu-n@nec.com>
diff --git a/src/xpath.c b/src/xpath.c
index a80f1f9..da1107d 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -226,9 +226,10 @@
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 @@
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