klangner / mapgen.rs

Map generator for games.
https://klangner.github.io/mapgen.rs/
Apache License 2.0
44 stars 5 forks source link

Guard against overflows. #38

Closed ndarilek closed 3 years ago

ndarilek commented 3 years ago

You're right, as defined, it cannot be negative. But it can be 0, and if you subtract 1 from that then you get an overflow. Rust does not protect you against that. You can't do:


let x: usize = -1;

But you can do:


let mut x: usize = 0;

x -= 1; // boom

I don't have a test case, but it happened to me this morning and crashed my game. I think you generally avoid it by surrounding the map with walls, but if you've got a map with open edges, it's definitely a thing that can happen.

klangner commented 3 years ago

I see. Let me try to prepare test for it tomorrow.
will you need new dist with it?

ndarilek commented 3 years ago

Yes please, thanks!

klangner commented 3 years ago

Thanks! There is a new version 0.5.2

ndarilek commented 3 years ago

Thank you!