Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined behaviors #14365

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/mapgen/mg_biome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,11 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po
// Carefully tune pseudorandom seed variation to avoid single node dither
// and create larger scale blending patterns similar to horizontal biome
// blend.
const u64 seed = pos.Y + (heat + humidity) * 0.9f;
// The calculation can be a negative floating point number, which is an
// undefined behavior if assigned to unsigned integer. Cast the result
// into signed integer before it is casted into unsigned integer to
// eliminate the undefined behavior.
const u64 seed = static_cast<s64>(pos.Y + (heat + humidity) * 0.9f);
appgurueu marked this conversation as resolved.
Show resolved Hide resolved
PcgRandom rng(seed);

if (biome_closest_blend && dist_min_blend <= dist_min &&
Expand Down
2 changes: 2 additions & 0 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ void ContentFeatures::reset()
has_on_construct = false;
has_on_destruct = false;
has_after_destruct = false;
floats = false;

/*
Actual data

Expand Down
3 changes: 1 addition & 2 deletions src/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ DigParams getDigParams(const ItemGroupList &groups,
// The actual number of uses increases
// exponentially with leveldiff.
// If the levels are equal, real_uses equals cap.uses.
u32 real_uses = cap.uses * pow(3.0, leveldiff);
real_uses = MYMIN(real_uses, U16_MAX);
const u32 real_uses = std::min<f64>(cap.uses * pow(3.0, leveldiff), U16_MAX);
result_wear = calculateResultWear(real_uses, initial_wear);
result_main_group = groupname;
}
Expand Down