#std.sort.sort with custom comparator causing integer overflows

1 messages · Page 1 of 1 (latest)

pure shale
#

indexes are usizes, in the case of 0 - 1 = UB

#

You need to define what you want with this

#

if 0 - 1 = 0 or 0 -1 = std.math.maxInt(usize)

#

or you don't what this to ever happen

#

after that you can use the saturate operator (saturate as in, 0 - 1 = 0 or for example in a byte (u8) having 255 + 1 = 255) or wrapping which as the name implies, is going to the max from 0 - 1 or going to the minimum number from maxValue + 1

#

I do recommend going with 0.10 just because is the more recent stable haha

#

will not exactly help haha, but oh well, outside that, what your code looks like either way