From 4c64a2f2a1b1caab0e482041da316cb74f7c9cd4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 30 Aug 2022 14:27:28 -0400 Subject: [PATCH] fix out-of-range memory access in sort function --- src/MESONT/pair_mesocnt.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MESONT/pair_mesocnt.cpp b/src/MESONT/pair_mesocnt.cpp index f6b4dc5592..4da33ccbd1 100644 --- a/src/MESONT/pair_mesocnt.cpp +++ b/src/MESONT/pair_mesocnt.cpp @@ -1424,10 +1424,11 @@ void PairMesoCNT::sort(int *list, int size) j = i; temp1 = list[j - 1]; temp2 = list[j]; - while (j > 0 && tag[temp1] > tag[temp2]) { + while (tag[temp1] > tag[temp2]) { list[j] = temp1; list[j - 1] = temp2; j--; + if (j == 0) break; temp1 = list[j - 1]; temp2 = list[j]; }