joern icon indicating copy to clipboard operation
joern copied to clipboard

Locals and loops not detected

Open itsacoderepo opened this issue 3 years ago • 1 comments

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;
}

itsacoderepo avatar Apr 14 '21 15:04 itsacoderepo

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>)

johannescoetzee avatar Aug 04 '21 12:08 johannescoetzee

outdated

itsacoderepo avatar Jan 15 '23 21:01 itsacoderepo