warning on unsafe cast

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

We've been bitten twice recently by bugs in our code where values were
implicitly cast to a smaller type - so we've been trying to find a
warning flag to enable warnings for possibly unsafe casts. 

For example:

int main(int argc, char *argv[]) {
  int i;
  short s;

  i = atoi(argv[1]);
  s = i;	// we'd like this line to cause a warning
  printf("%d\n", s);
  return 0;
}

I can understand why this isn't part of -Wall, but it seems like a
common enough problem that it would be useful to enable in a code
audit type build.  

Does anyone have any suggestions, or good reasons why this isn't
available as a warning?  Alternatively, if anyone can suggest a good
lint type program that would catch this (in C++ code) that would be
great.

I'd appreciate being cc'ed on any replies, I'm not subscribed to the
list.

Thanks,

Scott Lipcon




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux