Skip to content

Commit

Permalink
writer-json: do not needlessly duplicate messages in SARIF
Browse files Browse the repository at this point in the history
... when we have only one.

Reported-by: Jan Macku <[email protected]>
  • Loading branch information
lzaoral committed Feb 7, 2023
1 parent 4effa83 commit e335308
Show file tree
Hide file tree
Showing 6 changed files with 693 additions and 13,807 deletions.
46 changes: 24 additions & 22 deletions src/lib/writer-json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -368,32 +368,34 @@ void SarifTreeEncoder::appendDef(const Defect &def)
sarifEncodeMsg(&result, keyEvt.msg);

// other events
PTree flowLocs, relatedLocs;
for (unsigned i = 0; i < def.events.size(); ++i) {
if (def.events[i].event == "#")
sarifEncodeComment(&relatedLocs, def, i);
else
sarifEncodeEvt(&flowLocs, def, i);
}
if (1U < def.events.size()) {
PTree flowLocs, relatedLocs;
for (unsigned i = 0; i < def.events.size(); ++i) {
if (def.events[i].event == "#")
sarifEncodeComment(&relatedLocs, def, i);
else
sarifEncodeEvt(&flowLocs, def, i);
}

// locations
PTree tf;
tf.put_child("locations", flowLocs);
// locations
PTree tf;
tf.put_child("locations", flowLocs);

// threadFlows
PTree tfList;
appendNode(&tfList, tf);
PTree cf;
cf.put_child("threadFlows", tfList);
// threadFlows
PTree tfList;
appendNode(&tfList, tf);
PTree cf;
cf.put_child("threadFlows", tfList);

// codeFlows
PTree cfList;
appendNode(&cfList, cf);
result.put_child("codeFlows", cfList);
// codeFlows
PTree cfList;
appendNode(&cfList, cf);
result.put_child("codeFlows", cfList);

if (!relatedLocs.empty())
// our stash for comments
result.put_child("relatedLocations", relatedLocs);
if (!relatedLocs.empty())
// our stash for comments
result.put_child("relatedLocations", relatedLocs);
}

// append the `result` object to the `results` array
appendNode(&results_, result);
Expand Down
Loading

0 comments on commit e335308

Please sign in to comment.