--- /home/xavier/rpmvercmp.c 2008-05-14 21:29:29.000000000 +0200 +++ temp.c 2008-05-14 21:54:54.000000000 +0200 @@ -1,12 +1,21 @@ -int rpmvercmp(const char * a, const char * b) +int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b) { char oldch1, oldch2; - char abuf[strlen(a)+1], bbuf[strlen(b)+1]; + char abuf[64], bbuf[64]; char *str1 = abuf, *str2 = bbuf; char * one, * two; int rc; int isnum; + ALPM_LOG_FUNC; + + /* libalpm added code. ensure our strings are not null */ + if (!a) { + if (!b) return 0; + return -1; + } + if (!b) return 1; + /* easy comparison to see if versions are identical */ if (!strcmp(a, b)) return 0; @@ -18,8 +27,8 @@ /* loop through each version segment of str1 and str2 and compare them */ while (*one && *two) { - while (*one && !risalnum(*one)) one++; - while (*two && !risalnum(*two)) two++; + while (*one && !isalnum((int)*one)) one++; + while (*two && !isalnum((int)*two)) two++; /* If we ran to the end of either, we are finished with the loop */ if (!(*one && *two)) break; @@ -30,13 +39,13 @@ /* grab first completely alpha or completely numeric segment */ /* leave one and two pointing to the start of the alpha or numeric */ /* segment and walk str1 and str2 to end of segment */ - if (risdigit(*str1)) { - while (*str1 && risdigit(*str1)) str1++; - while (*str2 && risdigit(*str2)) str2++; + if (isdigit((int)*str1)) { + while (*str1 && isdigit((int)*str1)) str1++; + while (*str2 && isdigit((int)*str2)) str2++; isnum = 1; } else { - while (*str1 && risalpha(*str1)) str1++; - while (*str2 && risalpha(*str2)) str2++; + while (*str1 && isalpha((int)*str1)) str1++; + while (*str2 && isalpha((int)*str2)) str2++; isnum = 0; } @@ -86,10 +95,14 @@ } /* this catches the case where all numeric and alpha segments have */ - /* compared identically but the segment sepparating characters were */ + /* compared identically but the segment separating characters were */ /* different */ if ((!*one) && (!*two)) return 0; + /* libalpm added code. one version string may have a pkgrel number, the + * other may not. unless both have them, we ignore it and return 0. */ + if( (*one && *one == '-') || (*two && *two == '-')) return 0; + /* whichever version still has characters left over wins */ if (!*one) return -1; else return 1; }