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

Seeds above 32bit max int. #6898

Closed
Blauw67 opened this Issue Sep 11, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@Blauw67

Blauw67 commented Sep 11, 2018

When trying to create a new game with the same seed as an older game (even when it's from the same version), and the seed created with the older game is higher than the 32-bit integer, the one that will be created, will use the 32-bit (2^31 -1) as the seed.

image

(For example "C:\Program Files\OpenTTD\openttd.exe" -g -G 3584050622 will result in a game with seed 2147483647)

image

@LordAro

This comment has been minimized.

Show comment
Hide comment
@LordAro

LordAro Sep 11, 2018

Member

Found the issue:

case 'G': scanner->generation_seed = atoi(mgo.opt); break;

Specifically, generation_seed is a uint (32 bits), atoi is an int (32 bits).

Apparently it's undefined behaviour when atoi is given a number outside int bounds. Should probably be a strtoul or similar function

Member

LordAro commented Sep 11, 2018

Found the issue:

case 'G': scanner->generation_seed = atoi(mgo.opt); break;

Specifically, generation_seed is a uint (32 bits), atoi is an int (32 bits).

Apparently it's undefined behaviour when atoi is given a number outside int bounds. Should probably be a strtoul or similar function

MiguelHorta pushed a commit to MiguelHorta/OpenTTD that referenced this issue Oct 10, 2018

Miguel Miguel
Fix OpenTTD#6898: Replace atoi() with strtoul()
Normalize usage of generation_seed across all files
Add static_assert() to ensure correct type

MiguelHorta pushed a commit to MiguelHorta/OpenTTD that referenced this issue Oct 10, 2018

Miguel Miguel
Fix OpenTTD#6898: Replace atoi() with strtoul()
Normalize type and parsing of generation_seed across all files
Add assert_compile() to ensure correct type

MiguelHorta added a commit to MiguelHorta/OpenTTD that referenced this issue Oct 10, 2018

Fix OpenTTD#6898: Replace atoi() with strtoul()
Normalize type and parsing of generation_seed across all files
Add assert_compile() to ensure correct type

@orudge orudge closed this in e00908f Oct 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment