Skip to content

Commit

Permalink
remove the Length type
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingDepot committed Jul 10, 2024
1 parent 5985bf9 commit 44ef976
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ infix fun Any.cpgFlowsTo(that: Collection<Node>): Result =
is Array<*> -> this.anyResult { it?.cpgFlowsTo(that) }
is Node -> that.any { dataFlow(this, it).value }
is ParameterGroup -> this.parameters.allResult { it?.cpgFlowsTo(that) }
is Length -> checkLength(that)
else -> this in that.map { (it as Expression).evaluate() }
}
)
Expand All @@ -222,19 +221,6 @@ private fun Any.checkRange(that: Collection<Node>): Boolean {
}
}

private fun Length.checkLength(that: Collection<Node>): Result {
return Result.convert(
that.all {
val size = sizeof(it).value
if (size == -1) {
// Handle case where size could not be determined -> OPEN Finding
return OPEN
}
size in this.value
}
)
}

context(CokoBackend)
// TODO: better description
// TODO: in mark there is "..." to symbolize that the last arguments don't matter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,95 +81,22 @@ class ImplementationDslTest {
}
}

@Disabled("sizeof in CPG currently does not support InitListExpression as initializer")
@Test
fun `test Array Length`() {
val opX: MutableList<Op> = mutableListOf()
for (i in 0..3) {
opX += op {
"Foo.fun" {
signature(
Length(i..i)
)
}
}
}

val results = arrayOf(1, 0, 1, 2)
for (i in 0..3) {
with(lengthBackend) {
val nodes = opX[i].cpgGetNodes()
val validNodes = nodes.filter { it.value == Result.VALID }
assertEquals(
results[i],
validNodes.size,
"cpgGetNodes returned ${validNodes.size} node(s) instead of ${results[i]} nodes " +
"for the Op: ${opX[i]}."
)
assertEquals(
1,
nodes.filter { it.value == Result.OPEN }.size,
"cpgGetNodes did not return exactly one OPEN result as expected."
)
}
}
}

@Disabled("sizeof in CPG currently does not support MemberCallExpression as Initializer")
@Test
fun `test List Length`() {
val opX: MutableList<Op> = mutableListOf()
for (i in 0..3) {
opX += op {
"Foo.bar" {
signature(
Length(i..i)
)
}
}
}

val results = arrayOf(1, 0, 1, 2)
for (i in 0..3) {
with(lengthBackend) {
val nodes = opX[i].cpgGetNodes()
val validNodes = nodes.filter { it.value == Result.VALID }
assertEquals(
results[i],
validNodes.size,
"cpgGetNodes returned ${validNodes.size} node(s) instead of ${results[i]} nodes " +
"for the Op: ${opX[i]}."
)
assertEquals(
1,
nodes.filter { it.value == Result.OPEN }.size,
"cpgGetNodes did not return exactly one OPEN result as expected."
)
}
}
}

companion object {

lateinit var simpleBackend: CokoCpgBackend
lateinit var lengthBackend: CokoCpgBackend

@BeforeAll
@JvmStatic
fun startup() {
val classLoader = ImplementationDslTest::class.java.classLoader

val simpleFileResource = classLoader.getResource("ImplementationDslTest/SimpleJavaFile.java")
val lengthFileResource = classLoader.getResource("ImplementationDslTest/LengthJavaFile.java")

assertNotNull(simpleFileResource)
assertNotNull(lengthFileResource)

val simpleFile = simpleFileResource.toURI().toPath()
val lengthFile = lengthFileResource.toURI().toPath()

simpleBackend = CokoCpgBackend(config = createCpgConfiguration(simpleFile))
lengthBackend = CokoCpgBackend(config = createCpgConfiguration(lengthFile))
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ data class Type(val fqn: String)

data class ParamWithType(val param: Any, val type: Type)

/** Marks that we want to check the length of the argument, not the contents */
data class Length(val value: IntRange)

infix fun Any.withType(fqn: String) = ParamWithType(this, Type(fqn))

0 comments on commit 44ef976

Please sign in to comment.