Skip to content

Commit

Permalink
[c2cpg] Fixed more exceptions (#4736)
Browse files Browse the repository at this point in the history
- we had one stackoverflow in fullname
- evaluation.getOverload may return null
  • Loading branch information
max-leuthaeuser committed Jul 4, 2024
1 parent cb2bb5c commit d3b36e9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,22 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
}
return fn
case field: ICPPField =>
val fullNameNoSig = field.getQualifiedName.mkString(".")
val fn =
if (field.isExternC) {
field.getName
} else {
s"$fullNameNoSig:${safeGetType(field.getType)}"
}
return fn
case _: IProblemBinding =>
return ""
case _ =>
}
case declarator: CASTFunctionDeclarator =>
val fn = declarator.getName.toString
return fn
case definition: ICPPASTFunctionDefinition =>
case definition: ICPPASTFunctionDefinition if definition.getDeclarator.isInstanceOf[CPPASTFunctionDeclarator] =>
return fullName(definition.getDeclarator)
case x =>
}
Expand Down Expand Up @@ -367,13 +376,14 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
s"${fullName(f.getParent)}.${shortName(f)}"
case e: IASTElaboratedTypeSpecifier =>
s"${fullName(e.getParent)}.${ASTStringUtil.getSimpleName(e.getName)}"
case d: IASTIdExpression => ASTStringUtil.getSimpleName(d.getName)
case _: IASTTranslationUnit => ""
case u: IASTUnaryExpression => code(u.getOperand)
case x: ICPPASTQualifiedName => ASTStringUtil.getQualifiedName(x)
case other if other != null && other.getParent != null => fullName(other.getParent)
case other if other != null => notHandledYet(other); ""
case null => ""
case d: IASTIdExpression => ASTStringUtil.getSimpleName(d.getName)
case _: IASTTranslationUnit => ""
case u: IASTUnaryExpression => code(u.getOperand)
case x: ICPPASTQualifiedName => ASTStringUtil.getQualifiedName(x)
case other if other != null && other.getParent != null =>
fullName(other.getParent)
case other if other != null => notHandledYet(other); ""
case null => ""
}
fixQualifiedName(qualifiedName).stripPrefix(".")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ trait AstForExpressionsCreator(implicit withSchemaValidation: ValidationMode) {
createPointerCallAst(call, cleanType(safeGetType(call.getExpressionType)))
case functionType: ICPPFunctionType =>
functionNameExpr match {
case idExpr: CPPASTIdExpression =>
case idExpr: CPPASTIdExpression if idExpr.getName.getBinding.isInstanceOf[ICPPFunction] =>
val function = idExpr.getName.getBinding.asInstanceOf[ICPPFunction]
val name = idExpr.getName.getLastName.toString
val signature =
Expand Down Expand Up @@ -177,14 +177,16 @@ trait AstForExpressionsCreator(implicit withSchemaValidation: ValidationMode) {
val classFullName = cleanType(safeGetType(classType))
val fullName = s"$classFullName.$name:$signature"

val method = evaluation.getOverload.asInstanceOf[ICPPMethod]
val dispatchType =
if (method.isVirtual || method.isPureVirtual) {
DispatchTypes.DYNAMIC_DISPATCH
} else {
val dispatchType = evaluation.getOverload match {
case method: ICPPMethod =>
if (method.isVirtual || method.isPureVirtual) {
DispatchTypes.DYNAMIC_DISPATCH
} else {
DispatchTypes.STATIC_DISPATCH
}
case _ =>
DispatchTypes.STATIC_DISPATCH
}

}
val callCpgNode = callNode(
call,
code(call),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import io.shiftleft.codepropertygraph.generated.nodes.Literal
import io.shiftleft.semanticcpg.language.NoResolve
import io.shiftleft.semanticcpg.language.*

import java.nio.file.{Files, Path}

class CallTests extends C2CpgSuite {

implicit val resolver: NoResolve.type = NoResolve
Expand Down

0 comments on commit d3b36e9

Please sign in to comment.