coverity complains about a null-termination after a read,
so we terminate after exiting the do-while loop. The position
is conditional on whether idx is within the buffer or at the
end of the buffer.

Coverity issue: 337680
Fixes: a63504a90f ("examples/power: add JSON string handling")
CC: sta...@dpdk.org

Signed-off-by: David Hunt <david.h...@intel.com>

---
v2:
   * Move null termination outside of do-while.
---
 examples/vm_power_manager/channel_monitor.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/examples/vm_power_manager/channel_monitor.c 
b/examples/vm_power_manager/channel_monitor.c
index 971e4f2bc..03fdcd15a 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -822,6 +822,8 @@ read_json_packet(struct channel_info *chan_info)
                                break;
                } while (indent > 0);
 
+               json_data[idx + (idx < MAX_JSON_STRING_LEN - 1)] = '\0';
+
                if (indent > 0)
                        /*
                         * We've broken out of the read loop without getting
-- 
2.17.1

Reply via email to