aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Homerding <homerdin@gmail.com>2018-05-11 15:44:08 +0000
committerBrian Homerding <homerdin@gmail.com>2018-05-11 15:44:08 +0000
commit69e11d2d0302a2de890611a75a18d433c34e12ca (patch)
treeb6f39791b2f65b97cdb57d338b75820c4f22cee2
parentc61c9194c2194756bae7a5a7b338e945eca538e5 (diff)
[test-suite][ubsan] Fix UB in PENNANT in Mesh::initInvMap
PENNANT is accessing pcpair[-1] when i==0, however the value is not used when i==0 due to short-circuit evaluationi so the application behavior is not influenced. Adding a check to only load pcpair[i-1] when it will be used. git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@332099 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--MultiSource/Benchmarks/DOE-ProxyApps-C++/PENNANT/Mesh.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/MultiSource/Benchmarks/DOE-ProxyApps-C++/PENNANT/Mesh.cc b/MultiSource/Benchmarks/DOE-ProxyApps-C++/PENNANT/Mesh.cc
index 17e8d58f..d5624f06 100644
--- a/MultiSource/Benchmarks/DOE-ProxyApps-C++/PENNANT/Mesh.cc
+++ b/MultiSource/Benchmarks/DOE-ProxyApps-C++/PENNANT/Mesh.cc
@@ -273,8 +273,11 @@ void Mesh::initInvMap() {
sort(pcpair.begin(), pcpair.end());
for (int i = 0; i < numc; ++i) {
int p = pcpair[i].first;
- int pp = pcpair[i+1].first;
- int pm = pcpair[i-1].first;
+ int pp = pcpair[i+1].first;
+ int pm = 0;
+ // pm is only used when i != 0
+ if(i != 0)
+ pm = pcpair[i-1].first;
int c = pcpair[i].second;
int cp = pcpair[i+1].second;