I did a very lengthy evaluation of static analysis tools at my last job. In summary, cppcheck is pretty good and since it's free, why not. Of the paid tools, PVS-Studio was one of the best and very reasonably priced (not any more!) and rather expensive, but not as much as other tools (Unfortunately, instead of just listing a price, they play games with you, which means I really can't recommend them anymore--any company too chickenshit to put up plain prices doesn't deserve my business.) Of the super-expensive tools, the best, by a huge margin, was Coverity. It found almost all of the known issues, several critical issues none of the other tools found and almost three dozen minor issues. They are expensive, but worlds better than Klocwork and Parasoft.
Parasoft was pretty bad--their analysis tool did better than Klocwork, but missed several issues cppcheck caught and missed several known critical errors. Their product is excruciating slow and Parasoft's other tools were a disaster--several wouldn't even run. Klocwork was very buggy, missed several known bugs and their support was offensively useless (the evaluation went so badly that we terminated it early.)
One thing I concluded is that Parasoft and Klocwork specialize in selling to companies which must comply with weird rules for government work (for which there are hundreds of rules, like how switch statements must operate.) They do well at that, but not so well in finding actual bugs.
(Riverblade Software which makes Visual Lint, a tool which helps you deal with PC-Lint and Cppcheck--I don't much like it, but you may.)
Interesting you mentioned Parasoft: a couple of years ago (at a time when it was still relatively cheap) I chose it over lots of others based on a comparison report (which I unfortunately cannot locate any more). Back then it was indicated to be one of the best tools available for the Windows platform (the best affordable one at least), and indeed we got very good results.
That said, like what you stated about PVS, they don't openly state their prices, and now they're much more expensive than they used to be. Unfortunately this seems to be common practice for software tool makers nowadays Good thing there is open source! But still a pain when you really need to find the best tool for the job and end up wasting hours with inquiries only to find out the price tags are way beyond sanity!
Note however that Parasoft does instrument code for runtime analysis too, and we could uncover a number of very nasty memory leaks and bugs that we wouldn't have found in years without a tool, and not at all with static analysis alone! It's true they're not really great at static analysis, but that was never our main concern to start with!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
Re: Parasoft runtime analysis. This is one of the modules that failed during our evaluation. I can see how it used to be good, but it hasn't kept up with BoundsChecker. When I finally did get the runtime analysis to work, it presented two false positives!
One thing that really struck me during the evaluations is how poorly much of the software was written, especially for such expensive products. The number of obvious UI bugs in Klocwork were astounding (like toolbar buttons simply not working.) Klocwork and Parasoft both failed during installation! This is software which costs hundreds of thousands of dollars and the installer doesn't even work!
In normal situations, the following code stops timer as expected:
SetWaitabltTimer... // with duration 0 and period USER_TIMER_MINIMUM
Here, I mean 'normal' as 'not using socket calls'.
However, when the two conditions are met, CancelWaitableTimer does not stop timer. I've tried to find out why, in vain. The two conditions are:
- CSocket::Connect or CAsyncSocket::Connect was called
- the last SetWaitableTimer was called with Duration 0 and period USER_TIMER_MINUMUM
Actually USER_TIMER_MINUMUM is only to repeat the issue everytime in 100%.
If period is long enough, this issue happens irregularly.
That is, the following code fails to stop the timer.
SetWaitabltTimer... // with duration 0 and period USER_TIMER_MINIMUM
CSocket::Connect... // use Connect from CSocket or CAsyncSocket
Since it is too hard to post a complete source code here,
I would email the zipped project file if you send me an email to 'ehaerim at gmail dot com'.
First of all, what do you mean when you say "fails to stop the timer"? Does CancelWaitableTimer return an error, or does the execution stop at CSocket::Connect? Details, please.
(Also, it helps if you use the formatting options when posting, to separate text from code.)
Have you tried using Windows sockets directly? The MFC socket classes are very poorly implemented (see here for more details), and it's generally not that much more work to write your own. (Hm. Maybe I ought to dig out the implementation I wrote that I own and write it up as an article.)
> Orjan Westin wrote:
> First of all, what do you mean when you say "fails to stop the timer"?
> Does CancelWaitableTimer return an error, or does the execution stop at CSocket::Connect?
> Details, please.
CancelWaitableTimer(CWT) returns TRUE, but fails to stop the timer activated by SetWaitableTimer(SWT).
 You can test a variety of cases by modifying the first two #define statements. The most significant factor is the value of 'WAITABLETIMER_PERIDO'.
When it is
- USER_TIMER_MINIMUM * 1, ASSERT is triggered 100%.
- ~ USER_TIMER_MINIMUM * 50, ASSERT is triggered 100% as far as I tested.
- USER_TIMER_MINIMUM * 75, ASSERT is triggered 1~2 times out of 5 executions.
- USER_TIMER_MINIMUM * 100, ASSERT is triggered 1~2 times out of 10 executions.
The less significant but still affecting the result is the value of 'WAITABLETIMER_DUETIME_INITIALLY'.
When it is -1, much lower possibility of ASSERT.
Now, I believe you have all that you can play around.
In conclusion, all I can say is that CWT returning TRUE does not stop the timer immediately, but after the timer is signaled one more time for the following sequences:
- SetWaitableTimer is called with Duration 0 and period USER_TIMER_MINIMUM
- CSocket::Connect or CAsyncSocket::Connect is called
- CancelWaitableTimer is called
If you find out why CWT returning TRUE fails to stop the timer, please let me know.
The CancelWaitableTimer function does not change the signaled state of the timer. It stops the timer before it can be set to the signaled state and cancels outstanding APCs. Therefore, threads performing a wait operation on the timer remain waiting until they time out or the timer is reactivated and its state is set to signaled. If the timer is already in the signaled state, it remains in that state.
Your due time is set to the minimum 0xA value (one NT quantum). By the time you have called CancelWaitableTimer[^]... the timer is already in the signaled state.
It is the period that set to 0xA, not the initial due time.
The initial due time and period is intentionally set to 0 and 0xA to fire the timer 'immediately first time and ,after then, in the period of every 0xA milliseconds'.
Because of 'immediate due time', the timer gets signaled 'immediately' literally, and therefore 'case WAIT_OBJECT_0 + 1:' statement is the first statement executed without any delay.
Then socket Connect fails with WSAEWOULDBLOCK error and finally CWT call returns TRUE in sequence.
So, the overall code flow is like this:
Since the last CancelWaitableTimer returns TRUE, it should stop the timer right away, but the timer gets signaled just one more time. That's the issue!
Questions here are
- Why is the timer not stopped even after CWT returns TRUE?
- Why is the timer always signaled just one more time, not two or three and so on even if I admit the timer can be signaled more times after CWT returns TRUE(of course, I don't admit this, but just for the discussion of this issue, though)?
- What's the use of CWT if it is not guaranteed to stop the timer immediately? I'd rather set INFINITE due time and/or INFINITE period for SWT instead of using CWT.
I hope I miss something but unfortunately I don't know what are they.
Please be very specific and detail explaining what's going on about this issue.
Yes, by setting the initial due time to zero the waitable timer becomes immediately signaled. When the timer becomes signaled an APC is queued on your thread. When an APC is queued on your thread the kernel object representing the timer object has its reference count incremented. When you call CancelWaitableTimer if an APC is queued on your thread... a single APC is dequeued and the reference count is decremented by one and the timer is NOT cancelled.
Follow the instructions in my previous post to cancel your waitable timer.
Other thoughts... You can achieve the one-time timer fire by simply setting the
I am trying to extract the functions in a module by using the DBGHELP.LIB functions and loading only the PDB.
I can't seem to get SymEnumSymbols to invoke the callback at all. The SymEnumSymbols function returns 'success' as if it had done something. Trying various combinations of 'options' using SymSetOptions has not yielded results either. When I search The Internet almost always the result/examples seem to come back with examples where the EXE is loaded and running and has been attached to or at very least the process handle has been obtained.
Is having the process handle of the running EXE a requirement Microsoft has completely forgotten to state while using this 'Debug' library?
I need a 32 bit unsigned value just to hold the number of coding WTF I see in a day …
Actually, I was not trying to say anything, merely asking the obvious question. I had a good root through the documentation for this control and cannot find anything in MSDN that explains what is supposed to happen. I know that in a normal dialog it will work this way, but I don't have MFC so cannot make a sample to test what you are trying to do.