Let's Play a Game – find bugs in popular open-source projects
software.intel.com
software.intel.com
e.g. in "if a.length != a.length" the "correct" token is the first "a". Should really be anything in the whole expression.
The test is also pretty easy. I only know C and some Java and I figured most of the problems. The standout important questions to me were the memset and free ones.
Also, many quiz items are far away from the specialities of C++. It's stuff like duplicate expressions. Or a variable being subtracted from itself. Or a variable assigned to itself.
It's almost a case of boy-who-cried-wolf at this point. You get lots of warnings, but it works!
And they're not always due to the programmer being negligent. I've had many cases where something compiles cleanly on one box, but throws warnings on another because of a slightly different version of a compiler or library.
When I compile something and it runs through the entire process with not a single warning, it's truly a "...whoa" moment.
1. Broken windows theory. A code base full of warnings signals that nobody cares about anything. People will get better about finding and caring about the big things when they are forced to also care about the little things.
2. When your project has a "wall of warnings" there are real bugs hiding in there. I guarantee it and would bet money on it. Here's your opportunity to fix them and you don't even need QA to point them out. Your compiler is literally telling you.
3. When things compile on one box but not another, that's a big red flag that you have something platform-specific or library version-specific that WILL bite you some time later. unsigned-signed and sizeof(int) mismatches are good examples of this.
The whole "it compiles and works therefore it's done" mentality is some serious "second-year programming class" level shit, but it's everywhere. Good projects, where people care and have disciplined attitudes, discourage it.
Add it to your local build with "./configure CFLAGS=-Werror" or similar? That's great!
This is off the top of my head and likely clang specific: -Werror // Treat all warnings as errors -Wno-error=deprecated // Except deprecated warnings -Wno-error=deprecated-implementation // And these ones too
The deprecated-implementation warning flag should likely be made part of the deprecated warning group, but it's not yet. See the clang source for a helpful TODO? comment.
-Wclang-please-warn-about-warning-groups-that-are-missing-warnings ?
This "game" only tells half the story about static code analysis. Sure it's very impressive that all those bugs have been found and they are indeed hard to spot. However what's actually important would be the percentage of false-positives.
ccc-analyzer/c++-analyzer for clang/llvm would probably hit the 90-ish mark for ANSI C too.
And Coverity is not perfect: http://www.viva64.com/en/b/0408/#ID0EGMAC
Just disable JavaScript and reload the page, which will halt the countdown and display the solution. Then, when you've read what you need to know, re-enable JavaScript, reload the page, again, and then just click the place where the error is. Then click on the "Next Question"-button, disable JavaScript, again, and so on...
.right-fragment {
color: green;
font-weight: bold;
background-color: white;
font-size: 30px;
}The highest "badge" that you can earn by completing the 15 questions is <trollface> "won by tricking the system".
So: yes.
Although I do have to say, it's certainly kind of alarming, if not amusing, to see trivial bugs that slipped through the cracks in very many massively popular pieces of software.
The timer on the page put me under more stress than I'd like to admit. Maybe this is quite a good simulation of code review reality though, where you try cover lots of code in a small amount of time.
There's also the case of short little utilities. For something like strncmp (or at least my slightly naive version), I'd rather see code like
int strncmp(const char* s1, const char* s2, int n)
{
for(; n>0; s1++, s2++, n--) {
if (*s1 < *s2) {
return -1;
} else if (*s1 > *s2) {
return 1;
}
}
return 0;
}
than have code where someone attempted to come up with long "meaningful" names for each variable. There isn't really meaning here beyond "pointer_to_string1" and "pointer_to_string2", and longer names here do nothing but add visual clutter.The Plan9 community has to defend no highlights to n00bs.
Anyway, although I suggest these would be helped by a modern IDE and some style guides, I'd concede that since this is open source code, it's probably older than modern IDEs...
No no, you are supposed to pretend like you might be in a situation where this is no IDE!
Tech company interviews in a nutshell
Also even on 2016, many live on the AT&T world where IDEs are not welcome.
Those things can indeed cause a lot of harm but they are far less frequent in codebases not written by monkeys, compared to issues like undefined behaviour due to misunderstanding the language semantics, integer overflow, not checking whether a call has returned an error, etc.
Saying "don't write code with trivial errors" is almost like saying "don't write bugs". We all know how well that works. We must deal with the fact trivial bugs occur, and that they occur often; anything else is like hiding your head in the sand.
This is an argument in favor of static code analyzers.
"Test does not support mobile devices. It is very easy to miss with finger. We are working on new version of tests with better mobile devices support, new problems to solve etc. However, it is not implemented yet."
Since you have to select the bug in the code with the mouse, it's unusable on touchscreen mobile devices.
static int rr_cmp(uchar *a,uchar *b)
{
if (a[0] != b[0])
return (int) a[0] - (int) b[0];
if (a[1] != b[1])
return (int) a[1] - (int) b[1];
if (a[2] != b[2])
return (int) a[2] - (int) b[2];
if (a[3] != b[3])
return (int) a[3] - (int) b[3];
if (a[4] != b[4])
return (int) a[4] - (int) b[4];
if (a[5] != b[5])
return (int) a[1] - (int) b[5];
if (a[6] != b[6])
return (int) a[6] - (int) b[6];
return (int) a[7] - (int) b[7];
}
You are doing it wrong. You first need to figure out how to write code in a more readable fashion and not allow ugly things like the above in the codebase.This test gives the user a slightly unfair advantage, because you know where to look. If I was given the whole of the source file for any of these examples, I would probably never have found any bugs.
Accord.Net - http://www.viva64.com/en/b/0410/
Microsoft WPF Examples - http://www.viva64.com/en/b/0407/
Xamarin.Forms - http://www.viva64.com/en/b/0400/
Lucene.Net - http://www.viva64.com/en/b/0381/
Xenko Game Engine - http://www.viva64.com/en/b/0379/
Space Engineers - http://www.viva64.com/en/b/0376/
WPF examples by the Infragistics Company - http://www.viva64.com/en/b/0375/
CNTK tool kit - http://www.viva64.com/en/b/0372/
Sony C#/.NET component - http://www.viva64.com/en/b/0371/
IronPython and IronRuby - http://www.viva64.com/en/b/0367/
MonoDevelop - http://www.viva64.com/en/b/0366/
CoreFX - http://www.viva64.com/en/b/0365/
Roslyn - http://www.viva64.com/en/b/0363/
Still, in reality, knowing that your code has a bug is just one part of the story. Having huge legacy code base usually means you've got to fix the bugs as you go about your business implementing features/fixing other bugs. You cannot simply spend a year fixing bugs no-one actually cares about (because software was working well enough before).
So in this drive-by scenario IDE-integrated tool is much more useful than some offline report-generating tool. You see a warning live in your editor - you fix the issue - you move on. Very low effort and effective in the long run.
You can easy try PVS-Studio. Explanation about the PVS-Studio demo-version limitations: http://www.viva64.com/en/b/0395/
> You cannot simply spend a year fixing bugs no-one actually cares about (because software was working well enough before).
Yes. You can analysis only newly written code. Best Practices of using PVS-Studio. Now with C# support: http://www.viva64.com/en/b/0364/
(well, 1, and 2 where my spidey sense tingled but I clicked the wrong place)