diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression.kt index ccdebd8c04..b5e4cdb0ec 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Expression.kt @@ -87,7 +87,7 @@ abstract class Expression : Statement(), HasType { } /** Each Expression also has a MemoryAddress. */ - var memoryAddress = mutableSetOf() + var memoryAddress = mutableSetOf() override fun toString(): String { return ToStringBuilder(this, TO_STRING_STYLE) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPass.kt index a7cf525b7b..4c2faa3512 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPass.kt @@ -108,7 +108,8 @@ class PointsToPass(ctx: TranslationContext) : EOGStarterPass(ctx, orderDependenc is Expression -> { val newMemoryValues = value.elements.second.elements val newMemoryAddresses = - value.elements.first.elements.filterIsInstance() + value.elements.first.elements + as Collection /*.filterIsInstance()*/ if (newMemoryValues.isNotEmpty()) { key.prevDFG.clear() key.prevDFG.addAll(newMemoryValues) diff --git a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPassTest.kt b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPassTest.kt index 7ed40c44cc..5a7406fbf3 100644 --- a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPassTest.kt +++ b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/passes/PointsToPassTest.kt @@ -326,9 +326,7 @@ class PointsToPassTest { // Line 51 assertEquals(1, saLine51.memoryAddress.size) assertEquals( - (saLine51.base as? Reference) - ?.memoryAddress - ?.firstOrNull() + ((saLine51.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress) ?.fieldAddresses ?.filter { it.key == saLine51.refersTo?.name.toString() } ?.entries @@ -343,9 +341,7 @@ class PointsToPassTest { // Line 52 assertEquals(1, sbLine52.memoryAddress.size) assertEquals( - (sbLine52.base as? Reference) - ?.memoryAddress - ?.firstOrNull() + ((sbLine52.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress) ?.fieldAddresses ?.filter { it.key == sbLine52.refersTo?.name.toString() } ?.entries @@ -360,9 +356,7 @@ class PointsToPassTest { // Line 53 assertEquals(1, saLine53.memoryAddress.size) assertEquals( - (saLine53.base as? Reference) - ?.memoryAddress - ?.firstOrNull() + ((saLine53.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress) ?.fieldAddresses ?.filter { it.key == saLine53.refersTo?.name.toString() } ?.entries @@ -376,9 +370,7 @@ class PointsToPassTest { assertEquals(1, sbLine53.memoryAddress.size) assertEquals( - (sbLine53.base as? Reference) - ?.memoryAddress - ?.firstOrNull() + ((sbLine53.base as? Reference)?.memoryAddress?.firstOrNull() as? MemoryAddress) ?.fieldAddresses ?.filter { it.key == sbLine53.refersTo?.name.toString() } ?.entries @@ -459,8 +451,14 @@ class PointsToPassTest { // Line 66 assertEquals(1, n0Line66.memoryAddress.size) + assertTrue(n0Line66.arrayExpression.memoryAddress.first() is MemoryAddress) assertEquals( - n0Line66.arrayExpression.memoryAddress.first().fieldAddresses["0"]?.first(), + (n0Line66.arrayExpression.memoryAddress + .filterIsInstance() + .firstOrNull() + ?.fieldAddresses + ?.get("0") + ?.first() as MemoryAddress), n0Line66.memoryAddress.first() ) assertEquals(1, n0Line66.prevDFG.size) @@ -469,7 +467,12 @@ class PointsToPassTest { // Line 67 assertEquals(1, n0Line67.memoryAddress.size) assertEquals( - n0Line67.arrayExpression.memoryAddress.first().fieldAddresses["0"]?.first(), + (n0Line67.arrayExpression.memoryAddress + .filterIsInstance() + .firstOrNull() + ?.fieldAddresses + ?.get("0") + ?.first() as MemoryAddress), n0Line67.memoryAddress.first() ) assertEquals(1, n0Line67.prevDFG.size) @@ -478,7 +481,12 @@ class PointsToPassTest { // Line 68 assertEquals(1, n0Line68.memoryAddress.size) assertEquals( - n0Line68.arrayExpression.memoryAddress.first().fieldAddresses["0"]?.first(), + (n0Line68.arrayExpression.memoryAddress + .filterIsInstance() + .firstOrNull() + ?.fieldAddresses + ?.get("0") + ?.first() as MemoryAddress), n0Line68.memoryAddress.first() ) assertEquals(1, n0Line68.prevDFG.size) @@ -487,7 +495,12 @@ class PointsToPassTest { // Line 71 assertEquals(1, niLine71.memoryAddress.size) assertEquals( - niLine71.arrayExpression.memoryAddress.first().fieldAddresses["i"]?.first(), + (niLine71.arrayExpression.memoryAddress + .filterIsInstance() + .firstOrNull() + ?.fieldAddresses + ?.get("i") + ?.first() as MemoryAddress), niLine71.memoryAddress.first() ) assertEquals(1, niLine71.prevDFG.size) @@ -496,7 +509,12 @@ class PointsToPassTest { // Line 75 assertEquals(1, njLine75.memoryAddress.size) assertEquals( - njLine75.arrayExpression.memoryAddress.first().fieldAddresses["j"]?.first(), + (njLine75.arrayExpression.memoryAddress + .filterIsInstance() + .firstOrNull() + ?.fieldAddresses + ?.get("j") + ?.first() as MemoryAddress), njLine75.memoryAddress.first() ) // TODO: What are our expections for njLine75.prevDFG? I think null is fine, since we