joern
joern copied to clipboard
Locals and loops not detected
After importing the following code we are only seeing the first array for(int i = 0; i <= 2; i++)
and not the second. In addition we also only see i
as a local.
#include <iostream>
int main() {
// checking arrays
int array[3]{0,1,2};
for(int i = 0; i <= 2; i++) {
std::cout << array[i] << std::endl;
}
for (int i : array) {
std::cout << i << std::endl;
}
return 0;
}
The new c2cpg
frontend seems to solve the loop issue:
joern> cpg.controlStructure.l
res6: List[ControlStructure] = List(
ControlStructure(
... // truncated for brevity
code -> "for (int i = 0;i <= 2;i++)",
parserTypeName -> "CPPASTForStatement"
),
ControlStructure(
... // truncated for brevity
code -> "for (int i:array)",
parserTypeName -> "CPPASTRangeBasedForStatement"
)
)
It does not seem to handle the array definition, however:
joern> cpg.local.l
res7: List[Local] = List(
Local(
... // truncated for brevity
code -> "i",
typeFullName -> "int"
),
Local(
// truncated for brevity
name -> "i",
typeFullName -> "int"
)
)
The new frontend is still a WIP, so isn't the default yet. You can test it by running (from the joern repo):
> sbt stage
> ./c2cpg <input_dir> -o <outfile>
> ./joern
> importCpg(<outfile>)
outdated