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]; }