Skip to content

Commit

Permalink
bee_version_compare: Fix leading zero comparision
Browse files Browse the repository at this point in the history
fix a bug where pkg-1.02.3-0 was considered equal to pkg-1.2.4-0
because leading zeros caused the the algorithm to ignore and not
compare the rest of the string after detecting leading zeros.
  • Loading branch information
mariux committed Apr 10, 2013
1 parent 50c0be9 commit 69b0a0d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/bee_version_compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ int compare_version_strings(char *v1, char *v2) {
while(*a && *b && *a == *b) {
a++;
b++;

if (*a == *b)
continue;

/* skip leading zeros of numbers != 0 */
if (isdigit(*a) && isdigit(*b)) {
char *c;

for (c=a; *c == '0'; c++)
;
if (isdigit(*c))
a = c;

for (c=b; *c == '0'; c++)
;
if (isdigit(*c))
b = c;
}
}

/* strings are equal ; *a==*b==0*/
Expand All @@ -51,7 +69,8 @@ int compare_version_strings(char *v1, char *v2) {
if(isdigit(*b)) {
/* rewind string to first digit */
/* e.g. to compare 12 vs 100 and not 2 vs 00 */
while(a > v1 && isdigit(*(a-1))) {
while(a > v1 && isdigit(*(a-1)) &&
b > v2 && isdigit(*(b-1))) {
a--;
b--;
}
Expand Down

0 comments on commit 69b0a0d

Please sign in to comment.