From 5fb4942292c30be7225c4bbbc04fb3eecbf514fd Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 11 Sep 2018 22:14:24 +0200 Subject: json: Fix datatype_json() for literal level If a datatype doesn't provide a 'json' callback, datatype_json() uses fmemopen() to grab the output from 'print' callback. When doing so, reuse the existing output context instead of creating a dedicated one to make sure all output-related settings are exactly as expected. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- src/json.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/json.c b/src/json.c index 84bdaa39..bb1d0f2d 100644 --- a/src/json.c +++ b/src/json.c @@ -770,12 +770,13 @@ static json_t *datatype_json(const struct expr *expr, struct output_ctx *octx) return symbolic_constant_json(dtype->sym_tbl, expr, octx); if (dtype->print) { - struct output_ctx octx = { .numeric = 3 }; char buf[1024]; + FILE *ofp = octx->output_fp; - octx.output_fp = fmemopen(buf, 1024, "w"); - dtype->print(expr, &octx); - fclose(octx.output_fp); + octx->output_fp = fmemopen(buf, 1024, "w"); + dtype->print(expr, octx); + fclose(octx->output_fp); + octx->output_fp = ofp; if (buf[0] == '"') { memmove(buf, buf + 1, strlen(buf)); -- cgit v1.2.3