aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2018-04-05 15:29:10 +0200
committerFabian Groffen <grobian@gentoo.org>2018-04-05 15:29:10 +0200
commitccc0b73bade57d56a6512f7f174aa04c1018be5b (patch)
tree2893a7d8c9f821598d0bd7a5ece0a4d490435e9a
parenttests/atom_compare/Makefile: fail when there are differences (diff)
downloadportage-utils-ccc0b73bade57d56a6512f7f174aa04c1018be5b.tar.gz
portage-utils-ccc0b73bade57d56a6512f7f174aa04c1018be5b.tar.bz2
portage-utils-ccc0b73bade57d56a6512f7f174aa04c1018be5b.zip
atom_explode: get version letters comparing properly again
-rw-r--r--libq/atom_explode.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/libq/atom_explode.c b/libq/atom_explode.c
index faf24ffc..99a60d02 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;
}