for (const auto &Piece : Pieces) {
const PathDiagnosticLocation &P = Piece->getLocation();
Locations.push_back(createThreadFlowLocation(
- createLocation(createPhysicalLocation(P.asRange(),
- *P.asLocation().getFileEntry(),
- SMgr, Files),
+ createLocation(createPhysicalLocation(
+ P.asRange(),
+ *P.asLocation().getExpansionLoc().getFileEntry(),
+ SMgr, Files),
Piece->getString()),
calculateImportance(*Piece)));
}
{"locations",
json::Array{createLocation(createPhysicalLocation(
Diag.getLocation().asRange(),
- *Diag.getLocation().asLocation().getFileEntry(), SMgr, Files))}},
+ *Diag.getLocation().asLocation().getExpansionLoc().getFileEntry(),
+ SMgr, Files))}},
{"ruleIndex", Iter->getValue()},
{"ruleId", Diag.getCheckName()}};
}
{
"fileLocation": {
},
- "length": 686,
+ "length": 951,
"mimeType": "text/plain",
"roles": [
"resultFile"
"name": {
"text": "core.DivideZero"
}
+ },
+ {
+ "fullDescription": {
+ "text": "Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free()."
+ },
+ "helpUri": "https://clang-analyzer.llvm.org/available_checks.html#unix.Malloc",
+ "id": "unix.Malloc",
+ "name": {
+ "text": "unix.Malloc"
+ }
}
]
},
},
"region": {
"endColumn": 6,
- "endLine": 24,
+ "endLine": 34,
"startColumn": 3,
- "startLine": 24
+ "startLine": 34
}
}
}
},
"region": {
"endColumn": 18,
- "endLine": 9,
+ "endLine": 11,
"startColumn": 11,
- "startLine": 9
+ "startLine": 11
}
}
}
},
"region": {
"endColumn": 18,
- "endLine": 9,
+ "endLine": 11,
"startColumn": 11,
- "startLine": 9
+ "startLine": 11
}
}
}
},
"region": {
"endColumn": 6,
- "endLine": 25,
+ "endLine": 35,
"startColumn": 3,
- "startLine": 25
+ "startLine": 35
}
}
}
},
"region": {
"endColumn": 11,
- "endLine": 13,
+ "endLine": 15,
"startColumn": 3,
- "startLine": 13
+ "startLine": 15
}
}
}
},
"region": {
"endColumn": 9,
- "endLine": 14,
+ "endLine": 16,
"startColumn": 3,
- "startLine": 14
+ "startLine": 16
}
}
}
},
"region": {
"endColumn": 9,
- "endLine": 14,
+ "endLine": 16,
"startColumn": 3,
- "startLine": 14
+ "startLine": 16
}
}
}
},
"region": {
"endColumn": 13,
- "endLine": 18,
+ "endLine": 20,
"startColumn": 7,
- "startLine": 18
+ "startLine": 20
}
}
}
"region": {
"endColumn": 3,
"startColumn": 3,
- "startLine": 18
+ "startLine": 20
}
}
}
"region": {
"endColumn": 14,
"startColumn": 14,
- "startLine": 19
+ "startLine": 21
}
}
}
"region": {
"endColumn": 14,
"startColumn": 14,
- "startLine": 19
+ "startLine": 21
}
}
}
},
"ruleId": "core.DivideZero",
"ruleIndex": 2
+ },
+ {
+ "codeFlows": [
+ {
+ "threadFlows": [
+ {
+ "locations": [
+ {
+ "importance": "essential",
+ "location": {
+ "message": {
+ "text": "Memory is allocated"
+ },
+ "physicalLocation": {
+ "fileLocation": {
+ "fileIndex": 0,
+ },
+ "region": {
+ "endColumn": 24,
+ "endLine": 26,
+ "startColumn": 15,
+ "startLine": 26
+ }
+ }
+ }
+ },
+ {
+ "importance": "important",
+ "location": {
+ "message": {
+ "text": "Assuming 'i' is < 4"
+ },
+ "physicalLocation": {
+ "fileLocation": {
+ "fileIndex": 0,
+ },
+ "region": {
+ "endColumn": 12,
+ "endLine": 27,
+ "startColumn": 7,
+ "startLine": 27
+ }
+ }
+ }
+ },
+ {
+ "importance": "unimportant",
+ "location": {
+ "message": {
+ "text": "Taking true branch"
+ },
+ "physicalLocation": {
+ "fileLocation": {
+ "fileIndex": 0,
+ },
+ "region": {
+ "endColumn": 3,
+ "startColumn": 3,
+ "startLine": 27
+ }
+ }
+ }
+ },
+ {
+ "importance": "essential",
+ "location": {
+ "message": {
+ "text": "Potential leak of memory pointed to by 'mem'"
+ },
+ "physicalLocation": {
+ "fileLocation": {
+ "fileIndex": 0,
+ },
+ "region": {
+ "endColumn": 12,
+ "startColumn": 12,
+ "startLine": 28
+ }
+ }
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "locations": [
+ {
+ "physicalLocation": {
+ "fileLocation": {
+ "fileIndex": 0,
+ },
+ "region": {
+ "endColumn": 12,
+ "startColumn": 12,
+ "startLine": 28
+ }
+ }
+ }
+ ],
+ "message": {
+ "text": "Potential leak of memory pointed to by 'mem'"
+ },
+ "ruleId": "unix.Malloc",
+ "ruleIndex": 3
}
],
"tool": {
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.taint,debug.TaintTest,unix.Malloc %s -verify -analyzer-output=sarif -o - | %normalize_sarif | diff -U1 -b %S/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif -
#include "../Inputs/system-header-simulator.h"
+#include "../Inputs/system-header-simulator-for-malloc.h"
+#define ERR -1
int atoi(const char *nptr);
return 0;
}
+int leak(int i) {
+ void *mem = malloc(8);
+ if (i < 4)
+ return ERR; // expected-warning {{Potential leak of memory pointed to by 'mem'}}
+ free(mem);
+ return 0;
+}
+
int main(void) {
f();
g();
h(0);
+ leak(0);
return 0;
}