warning on unsafe cast
Scott Lipcon
slipcon@mercea.net
Fri Feb 27 14:30:00 GMT 2004
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
More information about the Gcc-help
mailing list