From 0c400f7df07ceec18b557f1a4ee07dc74671d711 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 17 Apr 2019 18:18:08 +0200 Subject: [PATCH] json: fix flag checks --- lib/formats/json.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/formats/json.cpp b/lib/formats/json.cpp index 086738e22..df09b2dd1 100644 --- a/lib/formats/json.cpp +++ b/lib/formats/json.cpp @@ -54,11 +54,15 @@ static json_t * json_pack_timestamps(struct io *io, struct sample *smp) { json_t *json_ts = json_object(); - if (io->flags & smp->flags & SAMPLE_HAS_TS_ORIGIN) - json_object_set(json_ts, "origin", json_pack("[ I, I ]", smp->ts.origin.tv_sec, smp->ts.origin.tv_nsec)); + if (io->flags & SAMPLE_HAS_TS_ORIGIN) { + if (smp->flags & SAMPLE_HAS_TS_ORIGIN) + json_object_set(json_ts, "origin", json_pack("[ I, I ]", smp->ts.origin.tv_sec, smp->ts.origin.tv_nsec)); + } - if (io->flags & smp->flags & SAMPLE_HAS_TS_RECEIVED) - json_object_set(json_ts, "received", json_pack("[ I, I ]", smp->ts.received.tv_sec, smp->ts.received.tv_nsec)); + if (io->flags & SAMPLE_HAS_TS_RECEIVED) { + if (smp->flags & SAMPLE_HAS_TS_RECEIVED) + json_object_set(json_ts, "received", json_pack("[ I, I ]", smp->ts.received.tv_sec, smp->ts.received.tv_nsec)); + } return json_ts; } @@ -101,13 +105,15 @@ static int json_pack_sample(struct io *io, json_t **j, struct sample *smp) json_smp = json_pack_ex(&err, 0, "{ s: o }", "ts", json_pack_timestamps(io, smp)); - if (io->flags & smp->flags & SAMPLE_HAS_SEQUENCE) { - json_t *json_sequence = json_integer(smp->sequence); + if (io->flags & SAMPLE_HAS_SEQUENCE) { + if (smp->flags & SAMPLE_HAS_SEQUENCE) { + json_t *json_sequence = json_integer(smp->sequence); - json_object_set(json_smp, "sequence", json_sequence); + json_object_set(json_smp, "sequence", json_sequence); + } } - if (io->flags & smp->flags & SAMPLE_HAS_DATA) { + if (io->flags & SAMPLE_HAS_DATA) { json_t *json_data = json_array(); for (unsigned i = 0; i < smp->length; i++) {