News for hackers. Stuff that matters.
Re:Rules for Developing Safety Critical Code [pdf] by jordanpg on Friday January 16, 2015 @07:31AM (#8898431)
> All code must be compiled, from the first day of development, with all compiler warnings enabled at the compiler’s most pedantic setting. All code must compile with these setting without any warnings. All code must be checked daily with at least one, but preferably more than one, state-of-the-art static source code analyzer and should pass the analyses with zero warnings.

Wow, am I ever frustrated by the summary ignoring of warnings I see going on around me. I spend my spare time at work making warnings go away and deleting uncommented @SupressWarnings from our codebase.

In a word, KISS. Another engineer designing critical systems for the US government coined that one, apparently [1].

[1] http://en.wikipedia.org/wiki/KISS_principle

Re:Rules for Developing Safety Critical Code [pdf] by jokoon on Friday January 16, 2015 @07:37AM (#8898467)
KISS needs to be taught, I really feel there should be a political movement around this principle.

Maybe one good exercise would be to ask programmers to write some program, and then let people vote on which code is the simplest to read and to understand.

Re:Rules for Developing Safety Critical Code [pdf] by tormeh on Friday January 16, 2015 @09:10AM (#8898951)
Then there's Clang's struct alignment warnings using -Weverything. "Oh no, your struct will have 3 bytes of padding!" Made me turn off -Werror. Some warnings can be ignored.
Re:Rules for Developing Safety Critical Code [pdf] by BudVVeezer on Friday January 16, 2015 @09:21AM (#8899006)
It's shocking to see how often people write code like: memcpy(somePtr, &myStructObj, 12);

So while that warning can certainly be useless information, it does definitely catch bugs. Unfortunately, the people who write code like the above are also more likely to be people who ignore warnings. ;-)

Re:Rules for Developing Safety Critical Code [pdf] by RogerL on Friday January 16, 2015 @09:45AM (#8899154)
Maybe you are being too specific in your example, and thus I am being nitpicky rather than helpful, but wouldn't that be caught by a static analyzer?
Re:Rules for Developing Safety Critical Code [pdf] by BudVVeezer on Friday January 16, 2015 @10:41AM (#8899533)
I just tried the following simple example:

  #include <string.h>

  struct S {
    int i;
    char c;
    int j;
  };

  void f(void) {
    struct S s1 = { 0, 0, 0 }, s2 = { 0, 0, 0 };
    memcpy(&s1, &s2, 9);
  }

  int main(void) {
    f();
    return 0;
  }
MSVC, Clang, and PC-Lint are all silent on the code (which is reasonable behavior since it's impossible to glean programmer intent from that snippet -- maybe the programmer really only wants the first nine bytes!). (Btw, yes, I am using the analyzer features for MSVC and Clang, not just relying on high warning levels.)
Re:Rules for Developing Safety Critical Code [pdf] by jacquesm on Friday January 16, 2015 @12:28PM (#8900226)
In some contexts that's actually an extremely useful warning.
Re:Rules for Developing Safety Critical Code [pdf] by tormeh on Friday January 16, 2015 @12:37PM (#8900279)
Sure, but my point is that -Werror is not always a good thing. You have a struct with 3 ints and then you add a bool and the compiler decides to pad the struct up to the size of 4 ints. When you have twelve of those structs obeying the -Werror is basically saying "stop the train! There's 36 bytes of wasted memory on the tracks", which is kinda ridiculous. I think it should be a note, not a warning, but until then -Werror is kinda broken for me.
Re:Rules for Developing Safety Critical Code [pdf] by jacquesm on Friday January 16, 2015 @12:46PM (#8900337)
You can selectively disable that particular warning with '-Wno-xxxx'. That way you get the ease of -Werror and you can get rid of those warnings that get in your way.
Re:Rules for Developing Safety Critical Code [pdf] by the_why_of_y on Saturday January 17, 2015 @02:26PM (#8905244)
Yes, that is one approach that may be useful for some more esoteric warnings.

All current compilers also have mechanisms to selectively ignore warnings via pragmas, like '#pragma GCC diagnostic ignored "-Wfoo"' in clang and GCC, which can be used to suppress instances of false positives of otherwise useful warnings.

https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

http://msdn.microsoft.com/en-us/library/aa273936.aspx

IMHO not using -Werror is just inexcusable.

Re:Rules for Developing Safety Critical Code [pdf] by fit2rule on Friday January 16, 2015 @11:55AM (#8900041)
All warnings are an indicator that things are not going as planned - which means some aspect of the code is either unplanned/misplanned/misunderstood. A warning is a clue that things are not as they seem..
Re:Rules for Developing Safety Critical Code [pdf] by raverbashing on Friday January 16, 2015 @08:18AM (#8898633)
Of course, this is not as simple as it seems.

1 - Some tools and libraries (like GTK - yeah) like to throw unfixable warnings. "Yeah, this platform is missing this feature so let's throw a warning"

2 - Sometimes fixing a warning results in something much more complicated than the original code. (see for example half of PyLint warnings)

So, for that to work it's important the tool warnings are good (and at least with GCC on C they usually are)

Re:Rules for Developing Safety Critical Code [pdf] by RogerL on Friday January 16, 2015 @09:48AM (#8899167)
When I did mission critical work we basically did not use libraries if at all possible. You need to know how everything works, and you need to be able to fix it. I'm pretty sure the NASA paper is written within that context.

But yes, that is a huge pet peeve of mine. I have all my QT header includes wrapped with pragmas to turn off warning because otherwise they spit out endless, useless warnings.

Re:Rules for Developing Safety Critical Code [pdf] by smackfu on Friday January 16, 2015 @09:48AM (#8899169)
3 - a compiler adds a new warning that triggers on existing code.

So when you go to do a minor fix, do you also touch other code that now triggers a warning?

Re:Rules for Developing Safety Critical Code [pdf] by raverbashing on Friday January 16, 2015 @09:58AM (#8899231)
True. Tell me about it.

Or worse, they break existing code (I've seen this happen with C++ on GCC)

Re:Rules for Developing Safety Critical Code [pdf] by ErrantX on Friday January 16, 2015 @08:56AM (#8898883)
A related class of problems is code coverage with unit tests; I have a regular argument here as to why we "aim for 80% code coverage but in practice accept 50-60%"
Re:Rules for Developing Safety Critical Code [pdf] by bprs on Friday January 16, 2015 @07:52AM (#8898519)
Any recommendation of a good static source code analyzer for C++ ?
Re:Rules for Developing Safety Critical Code [pdf] by RogerL on Friday January 16, 2015 @09:54AM (#8899201)
PVS Studio has always seemed to catch the most errors for me. It is by far worth the price if you s/w is at all important to you. But no tool is perfect. I also run cppcheck, Microsoft's VS (never liked that one much).

Haven't tried Clang because I am on Windows for my C++ stuff.

Re:Rules for Developing Safety Critical Code [pdf] by AndreyKarpov on Saturday January 17, 2015 @04:45AM (#8903978)
Updatable List of Open-Source Projects Checked with PVS-Studio: http://www.viva64.com/en/a/0084/