Skip to content

Commit

Permalink
xpath UPDATE use memstream instead of fixed buffer
Browse files Browse the repository at this point in the history
Fixes CESNET#2124

Signed-off-by: Toshikazu Nakayama <[email protected]>
  • Loading branch information
michalvasko committed Nov 1, 2023
1 parent 1ac8b41 commit 400cf3c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/xpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,32 @@ 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;
}

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
Expand Down

0 comments on commit 400cf3c

Please sign in to comment.