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

Dubious arithmetic #8

Closed
stedolan opened this issue Mar 23, 2015 · 1 comment
Closed

Dubious arithmetic #8

stedolan opened this issue Mar 23, 2015 · 1 comment

Comments

@stedolan
Copy link

mtime_stubs.c calculates time in nanoseconds using:

(now.tv_sec - start.tv_sec) * 1000000000 + (now.tv_nsec - start.tv_nsec)

This does arithmetic at type time_t. If that's 32-bit, this will overflow in a few seconds. It should use 64-bit arithmetic explicitly, either with casts or temporaries, e.g:

(int64)(now.tv_sec - start.tv_sec) * (int64)1000000000 + 
    (int64)(now.tv_nsec - start.tv_nsec)

or

int64 time = now.tv_sec - start.tv_sec;
time *= 1000000000;
time += now.tv_nsec - start.tv_nsec

My system has a 64-bit time_t, so I haven't actually tested any of this :)

@dbuenzli
Copy link
Owner

Damned ! Well spotted. Thanks.

I tested it, both the bug and the fix.

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

No branches or pull requests

2 participants