summaryrefslogtreecommitdiff
path: root/src/version.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-11-06 13:21:00 +0200
committerTimo Teras <timo.teras@iki.fi>2009-11-06 13:21:00 +0200
commitff45ff315294a853f5a65ae81e5a003d91f99d50 (patch)
tree37d55d881c6ba5360a6fa7bbcb3e828590126e8d /src/version.c
parent48930b9fe0fdd8b0a4d6e722992f99fa95b1399f (diff)
downloadapk-tools-ff45ff315294a853f5a65ae81e5a003d91f99d50.tar.gz
apk-tools-ff45ff315294a853f5a65ae81e5a003d91f99d50.tar.bz2
apk-tools-ff45ff315294a853f5a65ae81e5a003d91f99d50.tar.xz
apk-tools-ff45ff315294a853f5a65ae81e5a003d91f99d50.zip
version: fix remaining version comparisons
even more corner cases found which were broke. now all tests should pass.
Diffstat (limited to 'src/version.c')
-rw-r--r--src/version.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/version.c b/src/version.c
index 890ec7e..8ac7024 100644
--- a/src/version.c
+++ b/src/version.c
@@ -104,17 +104,15 @@ static int get_token(int *type, apk_blob_t *blob)
case TOKEN_SUFFIX:
for (v = 0; v < ARRAY_SIZE(pre_suffixes); v++) {
i = strlen(pre_suffixes[v]);
- if (i < blob->len &&
+ if (i <= blob->len &&
strncmp(pre_suffixes[v], blob->ptr, i) == 0)
break;
}
if (v < ARRAY_SIZE(pre_suffixes)) {
- nt = TOKEN_SUFFIX_NO;
v = v - ARRAY_SIZE(pre_suffixes);
break;
}
if (strncmp("p", blob->ptr, 1) == 0) {
- nt = TOKEN_SUFFIX_NO;
v = 1;
break;
}
@@ -125,7 +123,9 @@ static int get_token(int *type, apk_blob_t *blob)
}
blob->ptr += i;
blob->len -= i;
- if (nt != TOKEN_INVALID)
+ if (blob->len == 0)
+ *type = TOKEN_END;
+ else if (nt != TOKEN_INVALID)
*type = nt;
else
next_token(type, blob);
@@ -181,7 +181,7 @@ int apk_version_validate(apk_blob_t ver)
int apk_version_compare_blob(apk_blob_t a, apk_blob_t b)
{
- int at = TOKEN_DIGIT, bt = TOKEN_DIGIT;
+ int at = TOKEN_DIGIT, bt = TOKEN_DIGIT, tt;
int av = 0, bv = 0;
if (APK_BLOB_IS_NULL(a) || APK_BLOB_IS_NULL(b)) {
@@ -214,9 +214,11 @@ int apk_version_compare_blob(apk_blob_t a, apk_blob_t b)
/* leading version components and their values are equal,
* now the non-terminating version is greater unless it's a suffix
* indicating pre-release */
- if (at == TOKEN_SUFFIX && get_token(&at, &a) < 0)
+ tt = at;
+ if (at == TOKEN_SUFFIX && get_token(&tt, &a) < 0)
return APK_VERSION_LESS;
- if (bt == TOKEN_SUFFIX && get_token(&bt, &b) < 0)
+ tt = bt;
+ if (bt == TOKEN_SUFFIX && get_token(&tt, &b) < 0)
return APK_VERSION_GREATER;
if (at > bt)
return APK_VERSION_LESS;