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

Seeds above 32bit max int. #6898

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

Seeds above 32bit max int. #6898

Blauw67 opened this issue Sep 11, 2018 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Blauw67
Copy link

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 LordAro added good first issue Good for newcomers bug Something isn't working labels Sep 11, 2018
@LordAro
Copy link
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
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
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
Normalize type and parsing of generation_seed across all files
Add assert_compile() to ensure correct type
@orudge orudge closed this as completed in e00908f Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants