From 95911c197c4b48c061b6e2d8e4dd255bee05d1ab Mon Sep 17 00:00:00 2001 From: Patrick Gartung Date: Sun, 28 Feb 2021 11:07:40 -0600 Subject: [PATCH] Add check for func name in graph before calling has_path --- Utilities/StaticAnalyzers/scripts/callgraph.py | 2 +- .../StaticAnalyzers/scripts/create_statics_esd_reports.sh | 1 + Utilities/StaticAnalyzers/scripts/data-class-funcs.py | 4 ++-- Utilities/StaticAnalyzers/scripts/statics.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Utilities/StaticAnalyzers/scripts/callgraph.py b/Utilities/StaticAnalyzers/scripts/callgraph.py index 4abef0ddc2c69..5905ea7f6eb2a 100755 --- a/Utilities/StaticAnalyzers/scripts/callgraph.py +++ b/Utilities/StaticAnalyzers/scripts/callgraph.py @@ -43,7 +43,7 @@ callstacks=set() for tfunc in sorted(toplevelfuncs): for epfunc in sorted(epfuncs): - if nx.has_path(G,tfunc,epfunc) : + if tfunc in G and epfunc in G and nx.has_path(G,tfunc,epfunc) : path = nx.shortest_path(G,tfunc,epfunc) cs="" previous=str("") diff --git a/Utilities/StaticAnalyzers/scripts/create_statics_esd_reports.sh b/Utilities/StaticAnalyzers/scripts/create_statics_esd_reports.sh index 2b5e85be22302..8884dd71902fe 100755 --- a/Utilities/StaticAnalyzers/scripts/create_statics_esd_reports.sh +++ b/Utilities/StaticAnalyzers/scripts/create_statics_esd_reports.sh @@ -50,6 +50,7 @@ if [ ! -f ./callgraph.py ] cp -pv ${CMSSW_BASE}/src/Utilities/StaticAnalyzers/scripts/callgraph.py . cp -pv ${CMSSW_BASE}/src/Utilities/StaticAnalyzers/scripts/modules_in_ib.txt . fi +touch eventsetuprecord-get-all.txt eventsetuprecord-get.txt ./callgraph.py 2>&1 > eventsetuprecord-get-all.txt grep -f modules_in_ib.txt eventsetuprecord-get-all.txt | awk '{print $0"\n"}' > eventsetuprecord-get.txt diff --git a/Utilities/StaticAnalyzers/scripts/data-class-funcs.py b/Utilities/StaticAnalyzers/scripts/data-class-funcs.py index 4129df84f0637..8f265ca364df8 100755 --- a/Utilities/StaticAnalyzers/scripts/data-class-funcs.py +++ b/Utilities/StaticAnalyzers/scripts/data-class-funcs.py @@ -150,7 +150,7 @@ for badclass in sorted(badclasses): for dataclass in sorted(dataclasses): - if H.has_node(badclass) and H.has_node(dataclass): + if tfunc in H and dataclassfunc in H and H.has_node(badclass) and H.has_node(dataclass): if nx.has_path(H,dataclass, badclass) : print("Event setup data class '"+dataclass+"' contains or inherits from flagged class '"+badclass+"'.") flaggedclasses.add(dataclass) @@ -160,7 +160,7 @@ for dataclassfunc in sorted(dataclassfuncs): for tfunc in sorted(toplevelfuncs): - if nx.has_path(G,tfunc,dataclassfunc): + if tfunc in G and dataclassfunc in G and nx.has_path(G,tfunc,dataclassfunc): m = getfunc.match(dataclassfunc) n = handle.match(m.group(1)) if n : o = n.group(3) diff --git a/Utilities/StaticAnalyzers/scripts/statics.py b/Utilities/StaticAnalyzers/scripts/statics.py index 2d40de8705445..36efdc69a6e46 100755 --- a/Utilities/StaticAnalyzers/scripts/statics.py +++ b/Utilities/StaticAnalyzers/scripts/statics.py @@ -40,7 +40,7 @@ for tfunc in sorted(toplevelfuncs): for static in sorted(statics): - if nx.has_path(G,tfunc,static): + if tfunc in G and static in G and nx.has_path(G,tfunc,static): path = nx.shortest_path(G,tfunc,static) print("Non-const static variable \'"+re.sub(farg,"()",static)+"' is accessed in call stack '", end=' ')