The get_calling function sets the default parameter for cgraph as CallGraph(). Using an object as a default argument in a Python function results in the object being initialized only once. This can lead to unexpected results when the function is called multiple times.
A better approach would be to set the default value of cgraph to None and then initialize it within the function if it is not provided.
def get_calling(f: "ghidra.program.model.listing.Function", cgraph: CallGraph = None, depth: int = 0, visited: tuple = None, verbose=False, include_ns=True, start_time=None, max_run_time=None, max_depth=MAX_DEPTH):
if cgraph is None:
cgraph = CallGraph()
The
get_calling
function sets the default parameter forcgraph
asCallGraph()
. Using an object as a default argument in a Python function results in the object being initialized only once. This can lead to unexpected results when the function is called multiple times.A better approach would be to set the default value of cgraph to None and then initialize it within the function if it is not provided.