[nft PATCH 1/4] json: Fix datatype_json() for literal level

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxx>
---
 src/json.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/json.c b/src/json.c
index 84bdaa39c0d31..bb1d0f2d1bfcd 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));
-- 
2.18.0




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux