mach icon indicating copy to clipboard operation
mach copied to clipboard

ecs: Capacity calculation can overflow resulting in an infinite loop at runtime or a panic in debug/safe

Open tauoverpi opened this issue 3 years ago • 1 comments

see https://github.com/ziglang/zig/issues/12099

try storage.ensureTotalCapacity(gpa, math.maxInt(usize));

@addWithOverflow would solve this case.

https://github.com/hexops/mach/blob/f8f4dcf55fc0b7365abfa66304e1f781b5f4eb42/ecs/src/entities.zig#L130-L133

tauoverpi avatar Jul 13 '22 11:07 tauoverpi

lol i was already working on this

alichraghi avatar Jul 13 '22 12:07 alichraghi

new issue https://github.com/ziglang/zig/issues/12118

alichraghi avatar Oct 09 '22 15:10 alichraghi

@addWithOverflow would solve this case.

+| (saturated add) would probably be better

silversquirl avatar Oct 09 '22 17:10 silversquirl

Fixed!

alichraghi avatar Dec 27 '22 13:12 alichraghi

@alichraghi it looks like the code is still the same to me; we should update it to use a saturated add.

https://github.com/hexops/mach/blob/main/libs/ecs/src/entities.zig#L131-L132

Unless I'm missing something?

emidoots avatar Dec 27 '22 19:12 emidoots

sorry i thought this is an upstream issue (https://github.com/ziglang/zig/issues/12099)

alichraghi avatar Dec 27 '22 20:12 alichraghi