From 15c7b76c66cddfbf7465200476d7175e059d3102 Mon Sep 17 00:00:00 2001 From: Gianmarco Date: Thu, 28 Dec 2023 23:41:58 +0100 Subject: Fix cmpRunesIgnoreCase on system where sizeof(int) < 4. Fixes #23125. (#23138) Fixes an issue where importing the `strutils` module, or any other importing the `strutils` module, ends up with a compile time error on platforms where ints are less then 32-bit wide. The fix follows the suggestions made in #23125. --- lib/pure/unicode.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pure/unicode.nim b/lib/pure/unicode.nim index c8d18831a..4b557e16e 100644 --- a/lib/pure/unicode.nim +++ b/lib/pure/unicode.nim @@ -846,7 +846,12 @@ proc cmpRunesIgnoreCase*(a, b: openArray[char]): int {.rtl, extern: "nuc$1".} = # slow path: fastRuneAt(a, i, ar) fastRuneAt(b, j, br) - result = RuneImpl(toLower(ar)) - RuneImpl(toLower(br)) + when sizeof(int) < 4: + const lo = low(int).int32 + const hi = high(int).int32 + result = clamp(RuneImpl(toLower(ar)) - RuneImpl(toLower(br)), lo, hi).int + else: + result = RuneImpl(toLower(ar)) - RuneImpl(toLower(br)) if result != 0: return result = a.len - b.len -- cgit 1.4.1-2-gfad0