summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2023-02-28 14:39:09 +0200
committerTimo Teräs <timo.teras@iki.fi>2023-02-28 14:39:09 +0200
commit3df4a948a6904fca7ec9ca35e9b4e620f5bf6ded (patch)
tree5c59ce286ebf69d36a2e29a7606c4518f9509b19
parent3aa99faa83d08e45eff8a5cc95c4df16fb5bd257 (diff)
downloadapk-tools-3df4a948a6904fca7ec9ca35e9b4e620f5bf6ded.tar.gz
apk-tools-3df4a948a6904fca7ec9ca35e9b4e620f5bf6ded.tar.bz2
apk-tools-3df4a948a6904fca7ec9ca35e9b4e620f5bf6ded.tar.xz
apk-tools-3df4a948a6904fca7ec9ca35e9b4e620f5bf6ded.zip
version: fix leading zero stripping
Only the leading zeroes should be ignored. Handle properly if the version component is actually zero. fixes #10880
-rw-r--r--src/version.c6
-rw-r--r--test/version.data4
-rwxr-xr-xtest/version.sh8
3 files changed, 12 insertions, 6 deletions
diff --git a/src/version.c b/src/version.c
index f93e4c5..381330b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -84,7 +84,7 @@ static int64_t get_token(int *type, apk_blob_t *blob)
case TOKEN_DIGIT_OR_ZERO:
/* Leading zero digits get a special treatment */
if (blob->ptr[i] == '0') {
- while (i < blob->len && blob->ptr[i] == '0')
+ while (i+1 < blob->len && blob->ptr[i+1] == '0')
i++;
nt = TOKEN_DIGIT;
v = -i;
@@ -216,8 +216,8 @@ int apk_version_compare_blob_fuzzy(apk_blob_t a, apk_blob_t b, int fuzzy)
bv = get_token(&bt, &b);
#if 0
fprintf(stderr,
- "av=%d, at=%d, a.len=%d\n"
- "bv=%d, bt=%d, b.len=%d\n",
+ "av=%ld, at=%d, a.len=%ld\n"
+ "bv=%ld, bt=%d, b.len=%ld\n",
av, at, a.len, bv, bt, b.len);
#endif
}
diff --git a/test/version.data b/test/version.data
index bb1aa9e..8db0b45 100644
--- a/test/version.data
+++ b/test/version.data
@@ -727,3 +727,7 @@
1.0_p10-r0 > 1.0_p9-r0
0.1.0_alpha_pre2 < 0.1.0_alpha
1.0.0_pre20191002222144-r0 < 1.0.0_pre20210530193627-r0
+6.0_pre1 < 6.0
+6.1_pre1 < 6.1
+6.0_p1 > 6.0
+6.1_p1 > 6.1
diff --git a/test/version.sh b/test/version.sh
index 628a6eb..a2ee2b7 100755
--- a/test/version.sh
+++ b/test/version.sh
@@ -1,16 +1,18 @@
#!/bin/sh
fail=0
-cat version.data | while read a result b rest ; do
+while read a result b rest ; do
output="$(../src/apk version -t "$a" "$b")"
if [ "$output" != "$result" ] ; then
echo "$a $result $b, but got $output"
- fail=$(($fail+1))
+ fail=$((fail+1))
fi
-done
+done < version.data
if [ "$fail" = "0" ]; then
echo "OK: version checking works"
+else
+ echo "FAIL: $fail version checks failed"
fi
exit $fail