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 behavior during character creation #36470

Merged
merged 1 commit into from
Dec 26, 2019

Conversation

hexagonrecursion
Copy link
Contributor

Summary

SUMMARY: Bugfixes "Fixes undefined behavior during character creation"

Purpose of change

To reproduce the issue:

  1. Compile with clang UndefinedBehaviorSanitizer
  2. Try to create a new character
    When you press tab on the "profession" tab you will see on the console:
src/character.cpp:1114:66: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/character.cpp:1114:66 in 
src/character.cpp:1116:21: runtime error: -nan is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/character.cpp:1116:21 in

Note that even on an IEEE 754 compliant implementation this is UB because the result (NaN) is assigned to an integer without any checking.

This is triggered during character creation.
src/character.cpp:1114:66: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/character.cpp:1114:66 in 
src/character.cpp:1116:21: runtime error: -nan is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/character.cpp:1116:21 in
@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world labels Dec 26, 2019
@ZhilkinSerg ZhilkinSerg merged commit 9e77218 into CleverRaven:master Dec 26, 2019
@hexagonrecursion hexagonrecursion deleted the patch-2 branch December 26, 2019 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants