summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2024-12-16 07:19:45 -0800
committerKaz Kylheku <kaz@kylheku.com>2024-12-16 07:19:45 -0800
commit0815fd947ad1694b29b134fa5d7db89dcde41045 (patch)
treec037696a774b11b885738a0aa60d5fd2a4e9cfff
parentfa5dddc54edae346738d05f891b7d03476098c56 (diff)
downloadtxr-0815fd947ad1694b29b134fa5d7db89dcde41045.tar.gz
txr-0815fd947ad1694b29b134fa5d7db89dcde41045.tar.bz2
txr-0815fd947ad1694b29b134fa5d7db89dcde41045.zip
bug: string range length signed/unsigned.
* lib.c (length_str_range): On platforms where wchar_t is unsigned, we calculate bogus values for reversed ranges. On Android, gcc warns about the code, and the recently added tests fail. Let's cast the characters to long before doing the subtraction, which is the argument type of labs.
-rw-r--r--lib.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 11cf3340..512810f2 100644
--- a/lib.c
+++ b/lib.c
@@ -564,7 +564,8 @@ static val length_str_range(val from, val to)
cnum i;
for (i = 0; fs[i]; i++)
- out = mul(out, num(labs(ts[i] - fs[i]) + 1));
+ out = mul(out, num(labs(convert(long, ts[i]) -
+ convert(long, fs[i])) + 1));
gc_hint(from);
gc_hint(to);