Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
Date: Thu, 05 Apr 2018 13:31:17
Message-Id: 1522934950.ccc0b73bade57d56a6512f7f174aa04c1018be5b.grobian@gentoo
1 commit: ccc0b73bade57d56a6512f7f174aa04c1018be5b
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Thu Apr 5 13:29:10 2018 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Thu Apr 5 13:29:10 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ccc0b73b
7
8 atom_explode: get version letters comparing properly again
9
10 libq/atom_explode.c | 35 +++++++++++++++++++----------------
11 1 file changed, 19 insertions(+), 16 deletions(-)
12
13 diff --git a/libq/atom_explode.c b/libq/atom_explode.c
14 index faf24ff..99a60d0 100644
15 --- a/libq/atom_explode.c
16 +++ b/libq/atom_explode.c
17 @@ -256,26 +256,29 @@ atom_explode(const char *atom)
18 ret->suffixes[idx] = t;
19 }
20
21 - /* allow for 1 optional suffix letter, must be following a number */
22 - ptr = ret->PV + strlen(ret->PV);
23 - if (ptr[-1] >= 'a' && ptr[-1] <= 'z' &&
24 - ptr - 2 > ret->PV && ptr[-2] >= '0' && ptr[-2] <= '9')
25 - {
26 - ret->letter = ptr[-1];
27 - --ptr;
28 - }
29 + /* skip back to the "end" */
30 + for (ptr = ret->PV; *ptr != '\0' && *ptr != '_'; ptr++)
31 + ;
32 + ptr--;
33
34 - /* eat the trailing version number [-.0-9]+ */
35 - while (--ptr > ret->PV) {
36 - if (*ptr == '-') {
37 - *ptr = '\0';
38 - break;
39 - } else if (*ptr != '.' && !isdigit(*ptr))
40 + /* allow for 1 optional suffix letter */
41 + if (*ptr >= 'a' && *ptr <= 'z')
42 + ret->letter = *ptr--;
43 +
44 + /* eat the trailing version number [.0-9]+ */
45 + while (ptr > ret->PV) {
46 + if (*ptr != '.' && !isdigit(*ptr))
47 break;
48 + ptr--;
49 }
50
51 - ptr = stpcpy(ret->PVR, ret->PV);
52 - sprintf(ptr, "-r%i", ret->PR_int);
53 + if (ptr != ret->PV) {
54 + /* PV isn't exactly a number */
55 + ret->PV = ret->PVR = NULL;
56 + } else {
57 + ptr = stpcpy(ret->PVR, ret->PV);
58 + sprintf(ptr, "-r%i", ret->PR_int);
59 + }
60
61 return ret;
62 }