Skip to content

Commit fef49d1

Browse files
[c2cpg] Fix code string for locals from ICPPASTNamedTypeSpecifier (#5233)
1 parent 3ce044f commit fef49d1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreatorHelper.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
329329
}
330330

331331
private def typeForCPPAstNamedTypeSpecifier(s: ICPPASTNamedTypeSpecifier, stripKeywords: Boolean): String = {
332-
val tpe = safeGetBinding(s).map(_.toString).getOrElse(s.getRawSignature)
332+
val tpe = safeGetBinding(s) match {
333+
case Some(binding) if stripKeywords => binding.toString
334+
case _ => s.getRawSignature
335+
}
333336
cleanType(tpe, stripKeywords)
334337
}
335338

joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/querying/LocalQueryTests.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ class LocalQueryTests extends C2CpgSuite {
2929
}
3030

3131
"local query example 2" should {
32+
"allow to query for the local" in {
33+
val cpg = code(
34+
"""
35+
|class Foo {
36+
| static Foo* foo() {
37+
| static Foo bar;
38+
| return &bar;
39+
| }
40+
|}
41+
|""".stripMargin,
42+
"test.cpp"
43+
)
44+
val List(barLocal) = cpg.method.name("foo").local.nameExact("bar").l
45+
barLocal.typeFullName shouldBe "Foo"
46+
barLocal.code shouldBe "static Foo bar"
47+
}
48+
}
49+
50+
"local query example 3" should {
3251
val cpg = code("""
3352
| struct node {
3453
| int value;

0 commit comments

Comments
 (0)