Repository: joernio/joern (scala)

Issue:
newc: incorrect name for array type for some encodings
For `curl` at https://github.com/curl/curl , the type for the local `poll_client_rd` in `http_connect` is reported to be `"h:7628}[2]"` as opposed to `bool[2]`. Looks like an encoding issue?

Pull request description:
Fixes: https://github.com/joernio/joern/issues/854

Patch:
diff --git a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreatorHelper.scala b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreatorHelper.scala
index 5863c5c1355d..105a184ff32a 100644
--- a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreatorHelper.scala
+++ b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreatorHelper.scala
@@ -144,8 +144,13 @@ trait AstCreatorHelper {
     import org.eclipse.cdt.core.dom.ast.ASTSignatureUtil.getNodeSignature
     node match {
       case a: IASTArrayDeclarator if ASTTypeUtil.getNodeType(a).startsWith("? ") =>
-        val tpe = cleanType(getNodeSignature(node)).replace("[]", "")
-        val arr = ASTTypeUtil.getNodeType(node).replace("? ", "")
+        val tpe = getNodeSignature(a).replace("[]", "").strip()
+        val arr = ASTTypeUtil.getNodeType(a).replace("? ", "")
+        s"$tpe$arr"
+      case a: IASTArrayDeclarator if ASTTypeUtil.getNodeType(a).contains("} ") =>
+        val tpe = getNodeSignature(a).replace("[]", "").strip()
+        val nodeType = ASTTypeUtil.getNodeType(node)
+        val arr = nodeType.substring(nodeType.indexOf("["), nodeType.indexOf("]") + 1)
         s"$tpe$arr"
       case _: IASTIdExpression | _: IASTName | _: IASTArrayDeclarator =>
         cleanType(ASTTypeUtil.getNodeType(node))


Test patch:
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala
index ce1b69157a12..344922886601 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala
@@ -1417,6 +1417,15 @@ class AstCreationPassTests
       }
     }
 
+    "be correct for locals for array init" in TestAstOnlyFixture("""
+        |bool x[2] = { TRUE, FALSE };
+        |""".stripMargin) { cpg =>
+      inside(cpg.local.l) { case List(x) =>
+        x.name shouldBe "x"
+        x.typeFullName shouldBe "bool[2]"
+      }
+    }
+
     "be correct for array init without actual assignment" in TestAstOnlyFixture(
       """
         |int foo{1};