Errors with a few new compile flags.

Posted by Greven on Sat 03 Apr 2004 09:16 AM — 6 posts, 15,294 views.

Canada #0
I've been going through with a few compile flags, hoping to add find some buffer overflows or memory leaks, etc. I'm getting a warning as such:
Quote:
65: warning: overflow in implicit constant conversion
comm.c:65: warning: overflow in implicit constant conversion
comm.c:66: warning: overflow in implicit constant conversion
comm.c:66: warning: overflow in implicit constant conversion
comm.c:67: warning: overflow in implicit constant conversion
comm.c:67: warning: overflow in implicit constant conversion
and here is the corresponding code:
const char echo_off_str[] = { IAC, WILL, TELOPT_ECHO, '\0' };
const char echo_on_str[] = { IAC, WONT, TELOPT_ECHO, '\0' };
const char go_ahead_str[] = { IAC, GA, '\0' };
I'm assuming that its saying that these characters are not a singular character long, but from what I understand, telnet codes like these are all 1 character? Maybe someone could explain what this means?
USA #1
What compiler flag did you use to generate those warnings with?
Canada #2
-Wpointer-arith -Wstrict-prototypes -O2 -pedantic
I beleive that its the pedantic flag that does it, but I haven't confirmed. I was reading through some documents on buffer overflows and such, and it recommended these flags. Might not work with telnet code, though.
USA #3
Ah yes, the pedantic flag. The one flag I've yet to use on my code because the last time I tried it I got so many errors it was overwhelming. Perhaps I will revisit it now, for the curiosity factor :)
Australia Forum Administrator #4
IAC is defined as 0xFF which is effectively 255.

A char is a one-byte *signed* field, so effectively it can be from -128 to +127. Thus, 0xFF "overflows" a signed char byte.

One approach would be to define it:

const unsigned char echo_off_str[] = { IAC, WILL, TELOPT_ECHO, '\0' };


I think you then get other warnings which you need to work around. :) (eg. passing unsigned char to a routine that expects signed char).

Canada #5
Heh, yeah, that was exactly it. Thanks alot, had to do a couple casts, wasn't much, thanks.