minetest/src/mapgen
JosiahWI 8e5bd82c4d
fix integer overflow in mapgen (#11641)
* fix integer overflow in mapgen

Some calculations involving the magic seed had overflow because the result of an intermediate arithmetic step could not fit in an s32. By making the magic seed unsigned, the other operand in the equation will be cast to unsigned, and possibly other operands or intermediate operands. This will result in unexpected behavior if an operand is negative, which is technically possible, but logically should not happen.

* comment noise2d bitshift

While working through the code I was momentarily concerned that the right bitshift in noise2d could fill ones in some cases. It turns out that with signed integers, this is indeed true, but this one is shifting an unsigned integer, so the behavior is as expected. I put a comment here to clarify this, in case someone else wonders the same thing down the line.

* noise2d and noise3d unittests

I have added 3 tests each for noise2d and noise3d, testing all zero inputs, a very large seed (case which caused UB in the old implementation) and some fun primes I picked for no particular reason. This should be sufficient to demonstrate that the behavior of the new implementation has not changed. I used uniform initialization because it is a good feature of C++11. Please do not explode.

* uncomment the noise2d bitshift

This reverts commit 583b77ee9f1ad6bb77340ebb5ba51eb9a88ff51c. It's a
well-defined language semantic; it doesn't need to be commented.

* code cleanliness
2022-06-03 20:51:58 -04:00
..
cavegen.cpp Allow more than 255 biomes, document new maximum (#9855) 2020-05-20 22:16:14 +01:00
cavegen.h Allow more than 255 biomes, document new maximum (#9855) 2020-05-20 22:16:14 +01:00
CMakeLists.txt Move files to subdirectories (#6599) 2017-11-08 23:56:20 +01:00
dungeongen.cpp Spacing fixes 2022-04-08 14:55:21 +01:00
dungeongen.h Dungeons: Clean up parameters, improve structure variety (#8918) 2019-09-14 23:02:07 +01:00
mapgen_carpathian.cpp Avoid generating the same chunk more than once with multiple emerge threads. 2020-11-26 20:31:20 -08:00
mapgen_carpathian.h Give the Mapgen on each EmergeThread its own Biome/Ore/Deco/SchemManager copy 2020-05-05 19:26:59 +02:00
mapgen_flat.cpp Spacing fixes 2022-04-08 14:55:21 +01:00
mapgen_flat.h Mapgen Flat: Add caverns, disabled by default (#9913) 2020-08-05 05:00:00 +01:00
mapgen_fractal.cpp Avoid generating the same chunk more than once with multiple emerge threads. 2020-11-26 20:31:20 -08:00
mapgen_fractal.h Give the Mapgen on each EmergeThread its own Biome/Ore/Deco/SchemManager copy 2020-05-05 19:26:59 +02:00
mapgen_singlenode.cpp Avoid generating the same chunk more than once with multiple emerge threads. 2020-11-26 20:31:20 -08:00
mapgen_singlenode.h Give the Mapgen on each EmergeThread its own Biome/Ore/Deco/SchemManager copy 2020-05-05 19:26:59 +02:00
mapgen_v5.cpp Avoid generating the same chunk more than once with multiple emerge threads. 2020-11-26 20:31:20 -08:00
mapgen_v5.h Give the Mapgen on each EmergeThread its own Biome/Ore/Deco/SchemManager copy 2020-05-05 19:26:59 +02:00
mapgen_v6.cpp Remove a few unused functions reported by callcatcher (#11658) 2021-10-12 20:12:20 +02:00
mapgen_v6.h Remove a few unused functions reported by callcatcher (#11658) 2021-10-12 20:12:20 +02:00
mapgen_v7.cpp Fix some minor code issues all over the place 2020-12-24 13:44:54 +01:00
mapgen_v7.h Move Mapgen V7 river generation into the main generation loop (#10639) 2020-11-20 16:11:19 +00:00
mapgen_valleys.cpp Fix broken BiomeGen abstraction (#11107) 2021-03-23 15:43:26 +01:00
mapgen_valleys.h Give the Mapgen on each EmergeThread its own Biome/Ore/Deco/SchemManager copy 2020-05-05 19:26:59 +02:00
mapgen.cpp fix integer overflow in mapgen (#11641) 2022-06-03 20:51:58 -04:00
mapgen.h Removed some obsolete code (#10562) 2021-01-21 18:17:09 +00:00
mg_biome.cpp Spacing fixes 2022-04-08 14:55:21 +01:00
mg_biome.h Fix broken BiomeGen abstraction (#11107) 2021-03-23 15:43:26 +01:00
mg_decoration.cpp Allow more than 255 biomes, document new maximum (#9855) 2020-05-20 22:16:14 +01:00
mg_decoration.h Allow more than 255 biomes, document new maximum (#9855) 2020-05-20 22:16:14 +01:00
mg_ore.cpp Spacing fixes 2022-04-08 14:55:21 +01:00
mg_ore.h Fix function override warnings in mg_ore.h 2021-03-06 14:21:08 +01:00
mg_schematic.cpp Switch MapBlock compression to zstd (#10788) 2021-08-31 17:32:31 -07:00
mg_schematic.h Switch MapBlock compression to zstd (#10788) 2021-08-31 17:32:31 -07:00
treegen.cpp Fix some minor code issues all over the place 2020-12-24 13:44:54 +01:00
treegen.h Remove unused functions reported by cppcheck (#10463) 2020-10-05 09:07:33 +02:00