diff options
author | 2022-06-15 21:53:43 +0200 | |
---|---|---|
committer | 2022-06-15 21:53:43 +0200 | |
commit | 62503bbd9e82a5b0fdeec6e357a95e724ec3cef6 (patch) | |
tree | af33dc020e1d91eb1c4d7bb328e39fd10ddc234c | |
parent | main: ensure correct parsing of key-value pairs in ini-files (diff) | |
download | portage-utils-0.94.1.tar.gz portage-utils-0.94.1.tar.bz2 portage-utils-0.94.1.zip |
libq/atom: fix atom_compare for "0" version componentsv0.94.1
Bug: https://bugs.gentoo.org/852197
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r-- | libq/atom.c | 36 | ||||
-rw-r--r-- | tests/atom_compare/static.good | 1 | ||||
-rw-r--r-- | tests/atom_compare/static.tests | 1 |
3 files changed, 28 insertions, 10 deletions
diff --git a/libq/atom.c b/libq/atom.c index 50e9520c..31299f1b 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 6da5553b..83bf7ec7 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 168f3583..213fb5e1 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 |