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 in case of time overflow on 32-bit platforms #1774

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

d06alexandrov
Copy link
Contributor

Fixes #1762

Currently signed long int is used for storing current time in milliseconds (time is calculated by GetPlatformSpecificTimeInMillis()).
But on 32-bit platforms long could be a 32-bit number (e.g. C17 standard declares at 5.2.4.2.1 that long int should be at least 32 bits long).

Current unix timestamp in seconds is 31 bit long and timestamp in milliseconds is at least 41 bit long.

C/C++ standards declare that behavior of signed integer overflow is undefined (e.g. C17 example at 3.4.3).

The platform specific time is used only for calculating difference between end and start time. So, long could be replaced with unsigned long in that case without any negative effects.

@coveralls
Copy link

Coverage Status

coverage: 99.323%. remained the same
when pulling 0ade506 on d06alexandrov:fix_time_ub
into c3625dc on cpputest:master.

@basvodde basvodde merged commit acdbefb into cpputest:master Mar 28, 2024
66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined behaviour in GCC UtestPlatform.cpp
3 participants