News for hackers. Stuff that matters.
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.)