commit:     ccc0b73bade57d56a6512f7f174aa04c1018be5b
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Apr  5 13:29:10 2018 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Apr  5 13:29:10 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ccc0b73b

atom_explode: get version letters comparing properly again

 libq/atom_explode.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/libq/atom_explode.c b/libq/atom_explode.c
index faf24ff..99a60d0 100644
--- a/libq/atom_explode.c
+++ b/libq/atom_explode.c
@@ -256,26 +256,29 @@ atom_explode(const char *atom)
                ret->suffixes[idx] = t;
        }
 
-       /* allow for 1 optional suffix letter, must be following a number */
-       ptr = ret->PV + strlen(ret->PV);
-       if (ptr[-1] >= 'a' && ptr[-1] <= 'z' &&
-                       ptr - 2 > ret->PV && ptr[-2] >= '0' && ptr[-2] <= '9')
-       {
-               ret->letter = ptr[-1];
-               --ptr;
-       }
+       /* skip back to the "end" */
+       for (ptr = ret->PV; *ptr != '\0' && *ptr != '_'; ptr++)
+               ;
+       ptr--;
 
-       /* eat the trailing version number [-.0-9]+ */
-       while (--ptr > ret->PV) {
-               if (*ptr == '-') {
-                       *ptr = '\0';
-                       break;
-               } else if (*ptr != '.' && !isdigit(*ptr))
+       /* allow for 1 optional suffix letter */
+       if (*ptr >= 'a' && *ptr <= 'z')
+               ret->letter = *ptr--;
+
+       /* eat the trailing version number [.0-9]+ */
+       while (ptr > ret->PV) {
+               if (*ptr != '.' && !isdigit(*ptr))
                        break;
+               ptr--;
        }
 
-       ptr = stpcpy(ret->PVR, ret->PV);
-       sprintf(ptr, "-r%i", ret->PR_int);
+       if (ptr != ret->PV) {
+               /* PV isn't exactly a number */
+               ret->PV = ret->PVR = NULL;
+       } else {
+               ptr = stpcpy(ret->PVR, ret->PV);
+               sprintf(ptr, "-r%i", ret->PR_int);
+       }
 
        return ret;
 }

Reply via email to