aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNaïm Favier <n@monade.li>2022-08-19 00:59:04 +0200
committerNaïm Favier <n@monade.li>2022-08-19 01:00:10 +0200
commit8188b1d0abc2eba6497b5dc47f7e848cbacb7677 (patch)
tree7d6685f043e5443234fd6758a234c3e82a92b570 /src
parent7aa36ae79673d89e120a97a3c6fd9fbb46ea9da1 (diff)
json: write null on abnormal placeholder destruction
Avoids leaving dangling attributes like { "foo": } in case of exceptions.
Diffstat (limited to 'src')
-rw-r--r--src/libutil/json.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libutil/json.cc b/src/libutil/json.cc
index abe0e6e74..2f9e97ff5 100644
--- a/src/libutil/json.cc
+++ b/src/libutil/json.cc
@@ -193,7 +193,11 @@ JSONObject JSONPlaceholder::object()
JSONPlaceholder::~JSONPlaceholder()
{
- assert(!first || std::uncaught_exceptions());
+ if (first) {
+ assert(std::uncaught_exceptions());
+ if (state->stack != 0)
+ write(nullptr);
+ }
}
}