version: fix remaining version comparisons
even more corner cases found which were broke. now all tests should pass.cute-signatures
parent
48930b9fe0
commit
ff45ff3152
|
@ -104,17 +104,15 @@ static int get_token(int *type, apk_blob_t *blob)
|
||||||
case TOKEN_SUFFIX:
|
case TOKEN_SUFFIX:
|
||||||
for (v = 0; v < ARRAY_SIZE(pre_suffixes); v++) {
|
for (v = 0; v < ARRAY_SIZE(pre_suffixes); v++) {
|
||||||
i = strlen(pre_suffixes[v]);
|
i = strlen(pre_suffixes[v]);
|
||||||
if (i < blob->len &&
|
if (i <= blob->len &&
|
||||||
strncmp(pre_suffixes[v], blob->ptr, i) == 0)
|
strncmp(pre_suffixes[v], blob->ptr, i) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (v < ARRAY_SIZE(pre_suffixes)) {
|
if (v < ARRAY_SIZE(pre_suffixes)) {
|
||||||
nt = TOKEN_SUFFIX_NO;
|
|
||||||
v = v - ARRAY_SIZE(pre_suffixes);
|
v = v - ARRAY_SIZE(pre_suffixes);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strncmp("p", blob->ptr, 1) == 0) {
|
if (strncmp("p", blob->ptr, 1) == 0) {
|
||||||
nt = TOKEN_SUFFIX_NO;
|
|
||||||
v = 1;
|
v = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +123,9 @@ static int get_token(int *type, apk_blob_t *blob)
|
||||||
}
|
}
|
||||||
blob->ptr += i;
|
blob->ptr += i;
|
||||||
blob->len -= i;
|
blob->len -= i;
|
||||||
if (nt != TOKEN_INVALID)
|
if (blob->len == 0)
|
||||||
|
*type = TOKEN_END;
|
||||||
|
else if (nt != TOKEN_INVALID)
|
||||||
*type = nt;
|
*type = nt;
|
||||||
else
|
else
|
||||||
next_token(type, blob);
|
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 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;
|
int av = 0, bv = 0;
|
||||||
|
|
||||||
if (APK_BLOB_IS_NULL(a) || APK_BLOB_IS_NULL(b)) {
|
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,
|
/* leading version components and their values are equal,
|
||||||
* now the non-terminating version is greater unless it's a suffix
|
* now the non-terminating version is greater unless it's a suffix
|
||||||
* indicating pre-release */
|
* 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;
|
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;
|
return APK_VERSION_GREATER;
|
||||||
if (at > bt)
|
if (at > bt)
|
||||||
return APK_VERSION_LESS;
|
return APK_VERSION_LESS;
|
||||||
|
|
Loading…
Reference in New Issue