From: Alexei Sheplyakov Date: Sat, 8 Aug 2009 10:03:48 +0000 (+0300) Subject: shaker_sort, permutation_sign: fix invalid use of STL iterators. X-Git-Tag: release_1-6-0~72 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=694f839947982f5b12b6c629d5bab522c801630d shaker_sort, permutation_sign: fix invalid use of STL iterators. According to the standard incrementing end(), and decrementing begin() are ill-defined operations (see [lib.forward.iterators], [lib.bidirectional.iterators]). --- diff --git a/ginac/utils.h b/ginac/utils.h index 393c474f..e65bdae5 100644 --- a/ginac/utils.h +++ b/ginac/utils.h @@ -128,7 +128,9 @@ int permutation_sign(It first, It last) sign = -sign; } else if (!(*other < *i)) return 0; - --i; --other; + --i; + if (i != first) + --other; } if (!swapped) return sign; @@ -147,7 +149,9 @@ int permutation_sign(It first, It last) sign = -sign; } else if (!(*i < *other)) return 0; - ++i; ++other; + ++i; + if (i != last) + ++other; } if (!swapped) return sign; @@ -181,7 +185,9 @@ int permutation_sign(It first, It last, Cmp comp, Swap swapit) sign = -sign; } else if (!comp(*other, *i)) return 0; - --i; --other; + --i; + if (i != first) + --other; } if (!swapped) return sign; @@ -200,7 +206,9 @@ int permutation_sign(It first, It last, Cmp comp, Swap swapit) sign = -sign; } else if (!comp(*i, *other)) return 0; - ++i; ++other; + ++i; + if (i != last) + ++other; } if (!swapped) return sign; @@ -232,7 +240,9 @@ void shaker_sort(It first, It last, Cmp comp, Swap swapit) flag = other; swapped = true; } - --i; --other; + --i; + if (i != first) + --other; } if (!swapped) return; @@ -249,7 +259,9 @@ void shaker_sort(It first, It last, Cmp comp, Swap swapit) flag = other; swapped = true; } - ++i; ++other; + ++i; + if (i != last) + ++other; } if (!swapped) return;