-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Improper use of GetTickCount #3437
Comments
Won't that cause multi-threading issues? (which I then noticed you also mentioned) |
A proper fix would rather instead use GetTickCount64() if a new enough Windows version is used. |
While GetTickCount64 is an easy and proper fix for newer windows, it would still leave older windows vulnerable to overflow. If there continues to be a GetTickCount fallback, it should be correct. |
I won't disagree with that. But I can note that not a single person has reported an actual problem with this in the past so I don't consider it a very big problem... |
We recently accepted an enhancement on this function to use QueryPerformance instead of GetTickCount64 for Vista+ for higher resolution. The issue reported here AFAICT affects <=XP which has been a known issue (or, at least, I knew about it...). |
Ah right then GetTickCount64() isn't going to be useful since when that is available, a better solution is already used. The amount of users on <= XP that cares about this (minor) issue I would suspect is rather small. I'll nominate it for |
That still leaves the compiler warning |
We will happily appreciate and welcome patches fixing that. |
The warning is techinically correct. The analyzer is not smart enough to understand that the function is only called on versions of Windows that don't have GetTickCount64. You may be able to __pragma push and pop disabling the warning for just that area. |
Or maybe the |
That was the old approach. The current code supports compiling a single binary that will use QueryPerformanceCounter on Vista and GetTickCount on <= XP. The windows api level define could be checked, but that still wouldn't fix the case of compiling with the new tools but targeting WINVER 0x0500 |
Code analysis is only supported when compiling with the non-XP toolset, so the minimum The old approach was supporting only |
Just because you're using the new compiler and new windows headers doesn't mean you're defining That said, it may be worth eliding the run-time check if pre-vista support isn't being specified by _WIN32_WINNT. That doesn't invalidate the warning disable I'm adding, as it would still be possible to compile that code with the newer platform headers. |
Ah, wow! Last time I tried (probably with 0x0501 and in the VS 2012 era), I got hard compile errors when even including <windows.h>. At least it's unsupported [0] and the resulting application won't even run on the target Windows version when using ATL or not being extremely careful which APIs to use as some lost their target version conditions (which is why the XP toolsets use the Windows 7.1 SDK). [0] https://visualstudiomagazine.com/articles/2012/10/10/vs2012-update-preview-available.aspx |
e9ababd#diff-0a54b726bba1300aed45ad5693c349d1 has introduced a warning regression by switching from a compile-time check to a run-time check, but highlights a real bug.
I did this
Compiled for windows with msvc /analyze and many warnings enabled
I expected the following
Clean compilation. But instead,
And that warning is highlighting a real bug with this code. GetTickCount() should not be used as a monotonically increasing time source. Instead, you should store your own count and increment it by the change in GetTickCount().
Pseudocode:
This will have no overflow issues so long as it's called more frequently than once every 2^31-1 milliseconds. My pseudocode does have issues with multiple threads, though.
curl/libcurl version
251cabf
operating system
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64
The text was updated successfully, but these errors were encountered: