Skip to content

Commit 3628f2e

Browse files
committed
json-writer: do not use put_child("", ...) to append child
It triggers assertion failure in a debug build.
1 parent b2753ee commit 3628f2e

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/abstract-tree.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class AbstractTreeEncoder {
7070
virtual void writeTo(std::ostream &) = 0;
7171
};
7272

73+
template <typename TNode>
74+
void appendNode(TNode *pDst, const TNode &src)
75+
{
76+
pDst->push_back(std::make_pair("", src));
77+
}
78+
7379
template <typename TNode>
7480
bool findChildOf(TNode **pDst, TNode &node, const char *key)
7581
{

src/json-writer.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void SimpleTreeEncoder::appendDef(const Defect &def)
8181
evtNode.put<int>("verbosity_level", evt.verbosityLevel);
8282

8383
// append the event to the list
84-
evtList.push_back(std::make_pair("", evtNode));
84+
appendNode(&evtList, evtNode);
8585
}
8686

8787
// create a node for a single defect
@@ -110,7 +110,7 @@ void SimpleTreeEncoder::appendDef(const Defect &def)
110110
pDefects_ = &root_.put_child("defects", PTree());
111111

112112
// append the node to the list
113-
pDefects_->push_back(std::make_pair("", defNode));
113+
appendNode(pDefects_, defNode);
114114
}
115115

116116
void SimpleTreeEncoder::writeTo(std::ostream &str)
@@ -213,11 +213,11 @@ static void sarifEncodeEvt(PTree *pDst, const Defect &def, unsigned idx)
213213
PTree kind;
214214
kind.put<std::string>("", evt.event);
215215
PTree kindList;
216-
kindList.put_child("", kind);
216+
appendNode(&kindList, kind);
217217
tfLoc.put_child("kinds", kindList);
218218

219219
// append the threadFlowLocation object to the destination array
220-
pDst->push_back(std::make_pair("", tfLoc));
220+
appendNode(pDst, tfLoc);
221221
}
222222

223223
void SarifTreeEncoder::appendDef(const Defect &def)
@@ -233,7 +233,7 @@ void SarifTreeEncoder::appendDef(const Defect &def)
233233
PTree loc;
234234
sarifEncodeLoc(&loc, def, def.keyEventIdx);
235235
PTree keyLocs;
236-
keyLocs.put_child("", loc);
236+
appendNode(&keyLocs, loc);
237237
result.put_child("locations", keyLocs);
238238

239239
// key msg
@@ -250,17 +250,17 @@ void SarifTreeEncoder::appendDef(const Defect &def)
250250

251251
// threadFlows
252252
PTree tfList;
253-
tfList.put_child("", tf);
253+
appendNode(&tfList, tf);
254254
PTree cf;
255255
cf.put_child("threadFlows", tfList);
256256

257257
// codeFlows
258258
PTree cfList;
259-
cfList.put_child("", cf);
259+
appendNode(&cfList, cf);
260260
result.put_child("codeFlows", cfList);
261261

262262
// append the `result` object to the `results` array
263-
results_.push_back(std::make_pair("", result));
263+
appendNode(&results_, result);
264264
}
265265

266266
void SarifTreeEncoder::writeTo(std::ostream &str)
@@ -281,7 +281,7 @@ void SarifTreeEncoder::writeTo(std::ostream &str)
281281
PTree extProps;
282282
extProps.put_child("externalizedProperties", props);
283283
PTree propsList;
284-
propsList.put_child("", extProps);
284+
appendNode(&propsList, extProps);
285285
root.put_child("inlineExternalProperties", propsList);
286286
}
287287

@@ -291,7 +291,7 @@ void SarifTreeEncoder::writeTo(std::ostream &str)
291291

292292
// mandatory: runs
293293
PTree runs;
294-
runs.put_child("", run0_);
294+
appendNode(&runs, run0_);
295295
root.put_child("runs", runs);
296296

297297
// encode as JSON

0 commit comments

Comments
 (0)