commit:     62503bbd9e82a5b0fdeec6e357a95e724ec3cef6
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 15 19:53:43 2022 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Jun 15 19:53:43 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=62503bbd

libq/atom: fix atom_compare for "0" version components

Bug: https://bugs.gentoo.org/852197
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/atom.c                     | 36 ++++++++++++++++++++++++++----------
 tests/atom_compare/static.good  |  1 +
 tests/atom_compare/static.tests |  1 +
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 50e9520..31299f1 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -784,22 +784,38 @@ atom_compare_flg(const depend_atom *data, const 
depend_atom *query, int flags)
                                                         *ends1 != '_';
                                                         ends1++)
                                                        ;
+                                               if (ends1 != s1)
+                                                       ends1--;
                                                for (ends2 = s2;
                                                         *ends2 != '\0' &&
                                                         *ends2 != '.' &&
                                                         *ends2 != '_';
                                                         ends2++)
                                                        ;
-                                               /* 3.3L2-3: remove *trailing* 
zeros */
-                                               for (ends1--; ends1 > s1 && 
*ends1 == '0'; ends1--)
-                                                       ;
-                                               for (ends2--; ends2 > s2 && 
*ends2 == '0'; ends2--)
-                                                       ;
-                                               /* 3.3L4 ASCII stringwise 
comparison */
-                                               n1 = ends1 - s1;
-                                               n2 = ends2 - s2;
-                                               n1 = strncmp(s1, s2, n1 > n2 ? 
n1 : n2);
-                                               n2 = 0;
+                                               if (ends2 != s2)
+                                                       ends2--;
+                                               /* bug 852197: leading 0 means 
something else
+                                                *              must follow */
+                                               if (ends1 - s1 > 1 || ends2 - 
s2 > 1) {
+                                                       /* 3.3L2-3: remove 
*trailing* zeros */
+                                                       for (; ends1 > s1 && 
*ends1 == '0'; ends1--)
+                                                               ;
+                                                       for (; ends2 > s2 && 
*ends2 == '0'; ends2--)
+                                                               ;
+                                                       /* 3.3L4 ASCII 
stringwise comparison */
+                                                       n1 = ends1 - s1;
+                                                       n2 = ends2 - s2;
+                                                       n1 = strncmp(s1, s2, n1 
> n2 ? n1 : n2);
+                                                       n2 = 0;
+                                               } else {
+                                                       /* repeat of 3.3#L9 
(else case below) */
+                                                       n1 = strtoll(s1, 
&ends1, 10);
+                                                       if (ends1 == s1)
+                                                               n1 = -1;
+                                                       n2 = strtoll(s2, 
&ends2, 10);
+                                                       if (ends2 == s2)
+                                                               n2 = -1;
+                                               }
                                        } else {  /* 3.3#L9 */
                                                n1 = strtoll(s1, &ends1, 10);
                                                if (ends1 == s1)

diff --git a/tests/atom_compare/static.good b/tests/atom_compare/static.good
index 6da5553..83bf7ec 100644
--- a/tests/atom_compare/static.good
+++ b/tests/atom_compare/static.good
@@ -52,3 +52,4 @@ a-1 != =a-1.2z*
 a-1_alpha1 == =a-1*
 a-1 != =a-1_alpha1*
 a-1_alpha-r1 == =a-1_alpha*
+a-3.10.5 == >=a-3.10.0_p1_r1

diff --git a/tests/atom_compare/static.tests b/tests/atom_compare/static.tests
index 168f358..213fb5e 100644
--- a/tests/atom_compare/static.tests
+++ b/tests/atom_compare/static.tests
@@ -52,3 +52,4 @@ a-1 =a-1.2z*
 a-1_alpha1 =a-1*
 a-1 =a-1_alpha1*
 a-1_alpha-r1 =a-1_alpha*
+a-3.10.5 >=a-3.10.0_p1_r1

Reply via email to