version: fix comparison against empty version
parent
7695ed82be
commit
0b9bfa8d52
|
@ -75,6 +75,11 @@ static int get_token(int *type, apk_blob_t *blob)
|
||||||
static const char *pre_suffixes[] = { "alpha", "beta", "pre", "rc" };
|
static const char *pre_suffixes[] = { "alpha", "beta", "pre", "rc" };
|
||||||
int v = 0, i = 0, nt = TOKEN_INVALID;
|
int v = 0, i = 0, nt = TOKEN_INVALID;
|
||||||
|
|
||||||
|
if (blob->len <= 0) {
|
||||||
|
*type = TOKEN_END;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (*type) {
|
switch (*type) {
|
||||||
case TOKEN_DIGIT_OR_ZERO:
|
case TOKEN_DIGIT_OR_ZERO:
|
||||||
/* Leading zero digits get a special treatment */
|
/* Leading zero digits get a special treatment */
|
||||||
|
@ -201,13 +206,13 @@ int apk_version_compare_blob(apk_blob_t a, apk_blob_t b)
|
||||||
return APK_VERSION_LESS;
|
return APK_VERSION_LESS;
|
||||||
if (av > bv)
|
if (av > bv)
|
||||||
return APK_VERSION_GREATER;
|
return APK_VERSION_GREATER;
|
||||||
if (at < bt)
|
|
||||||
return get_token(&at, &a) < 0 ?
|
/* at and bt are the next expected token type */
|
||||||
APK_VERSION_LESS : APK_VERSION_GREATER;
|
if (at == bt)
|
||||||
if (bt < at)
|
return APK_VERSION_EQUAL;
|
||||||
return get_token(&bt, &b) > 0 ?
|
if (at < bt || bt == TOKEN_INVALID)
|
||||||
APK_VERSION_LESS : APK_VERSION_GREATER;
|
return APK_VERSION_GREATER;
|
||||||
return APK_VERSION_EQUAL;
|
return APK_VERSION_LESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int apk_version_compare(const char *str1, const char *str2)
|
int apk_version_compare(const char *str1, const char *str2)
|
||||||
|
|
Loading…
Reference in New Issue