summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-09-11 22:14:24 +0200
committerFlorian Westphal <fw@strlen.de>2018-09-13 10:41:34 +0200
commit5fb4942292c30be7225c4bbbc04fb3eecbf514fd (patch)
treece23433c8b4d19e508434b16d19605e65c1a4d1b
parentd90daac1aec5f5233cecaffdcc2847b87896aef7 (diff)
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 <phil@nwl.cc> Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r--src/json.c9
1 files 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));