diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-04-17 21:08:36 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-04-17 21:08:36 +0000 |
commit | 0f7a45f60e182c1aea429fa2109e9caac9152eab (patch) | |
tree | 576aadb53b3e52f26282162895a59231c5bc40b7 | |
parent | cf0c149eff981c58650b3961d20be87018d8d606 (diff) | |
download | portage-0f7a45f60e182c1aea429fa2109e9caac9152eab.tar.gz portage-0f7a45f60e182c1aea429fa2109e9caac9152eab.tar.bz2 portage-0f7a45f60e182c1aea429fa2109e9caac9152eab.zip |
Bug #266493 - Never return a long from vercmp() since that can trigger an
OverflowError if it's returned by a __cmp__ implementation. Thanks to
Douglas Anderson <dja@gendja.com> for the initial patch. I've modified it
to use the (a > b) - (a < b) construct as suggested in the py3k docs, since
cmp() is no longer supported in py3k.
svn path=/main/trunk/; revision=13353
-rw-r--r-- | pym/portage/versions.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/pym/portage/versions.py b/pym/portage/versions.py index d3f256dc0..13ce47897 100644 --- a/pym/portage/versions.py +++ b/pym/portage/versions.py @@ -124,9 +124,12 @@ def vercmp(ver1, ver2, silent=1): vercmp_cache[mykey] = 1 return 1 elif list1[i] != list2[i]: - vercmp_cache[mykey] = list1[i] - list2[i] - return list1[i] - list2[i] - + a = list1[i] + b = list2[i] + rval = (a > b) - (a < b) + vercmp_cache[mykey] = rval + return rval + # main version is equal, so now compare the _suffix part list1 = match1.group(6).split("_")[1:] list2 = match2.group(6).split("_")[1:] @@ -142,7 +145,11 @@ def vercmp(ver1, ver2, silent=1): else: s2 = suffix_regexp.match(list2[i]).groups() if s1[0] != s2[0]: - return suffix_value[s1[0]] - suffix_value[s2[0]] + a = suffix_value[s1[0]] + b = suffix_value[s2[0]] + rval = (a > b) - (a < b) + vercmp_cache[mykey] = rval + return rval if s1[1] != s2[1]: # it's possible that the s(1|2)[1] == '' # in such a case, fudge it. @@ -154,9 +161,11 @@ def vercmp(ver1, ver2, silent=1): r2 = int(s2[1]) except ValueError: r2 = 0 - if r1 - r2: - return r1 - r2 - + rval = (r1 > r2) - (r1 < r2) + if rval: + vercmp_cache[mykey] = rval + return rval + # the suffix part is equal to, so finally check the revision if match1.group(10): r1 = int(match1.group(10)) @@ -166,8 +175,9 @@ def vercmp(ver1, ver2, silent=1): r2 = int(match2.group(10)) else: r2 = 0 - vercmp_cache[mykey] = r1 - r2 - return r1 - r2 + rval = (r1 > r2) - (r1 < r2) + vercmp_cache[mykey] = rval + return rval def pkgcmp(pkg1, pkg2): """ |