Fixing kernel compilation warnings

Alexander Vlasenko (ukrgym@ilyichevsk.odessa.ua)
Wed, 9 Dec 1998 16:05:41 +0200


Hi kernel hackers,

I am a fresh newbie with usual newbie stuff.

I recompiled kernel for the first time and, being a kind of
'purist' in programming (I will do anything for my programs
to compile without _warnings_), want to show you a few places
in kernel source which produce them. Surely you could fix that
yourself but maybe you're busy with something much more important.

Note: I compiled kernel 2.0.35 with fixes and it runs ok.
(I do not have any 2.1.xx kernel yet).
I hope that these fixes won't break anything :-)

--- include/asm-i386/string.h ---
switch (n % 4) {
case 0: COMMON(""); return to;
case 1: COMMON("\n\tmovsb"); return to;
case 2: COMMON("\n\tmovsw"); return to;
case 3: COMMON("\n\tmovsw\n\tmovsb"); return to;
}
}
...
switch (count % 4) {
case 0: COMMON(""); return s;
case 1: COMMON("\n\tstosb"); return s;
case 2: COMMON("\n\tstosw"); return s;
case 3: COMMON("\n\tstosw\n\tstosb"); return s;
}
}

Replace "case 3:" with "default:"
This will eliminate warning about non-returning a value.
(gcc does not understand that execution will take some case label
in any case :-) and will never fall through).

--- include/linux/ctype.h ---
#define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D))
...
#define isxdigit(c) ((_ctype+1)[c]&(_D|_X))

#define isascii(c) (((unsigned) c)<=0x7f)
#define toascii(c) (((unsigned) c)&0x7f)

#define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp)
#define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp)

Replace [c] by [(unsigned)(c)] in isalnum... isxdigit def.
This will eliminate a warning "subscript is char" in various places.
On system with signed char [c] can lead to serious trouble
when c is in 'x80'..'xFF' range (c is negative).

Replace c by (c) in isascii & toascii. Imagine what will
happen if someone will write isascii(a+b): cast will
apply only to 'a'! This probably will work ok in any imaginable
case but I'm a 'purist'...

EOF (#defined to -1) handling should be ok with the fix
(it will just wraps to _ctype[0]).

to be chkd: DOS Borland compilers do automatic integral promotion
to int first, thus making (unsigned)(char)'0xFF' == (unsigned)(-1) !!!
(i.e. such fix will do nothing for Borland compiler).
Don't know about gcc.

I don't like toupper/tolower either. Use of global variable here?!
There ought to be a better way. Inline funcs?

extern inline char tolower(char c) { return isupper(c) ? c-('A'-'a') :
c; }

I leaved it as it is fearing incorrect EOF handling.
(btw I never liked an idea of using that EOF in the first place).

If you gonna insert the fix into kernel, I'm interested in your
opinion.
If it doesn't work, let me know!
Flames like "it is totally unimportant" >/dev/null.

For kernel maintainers: sorry if I bothered you with this tiny stuff.
If I have to post such things to some more appropriate
place pls let me know.

--
Denis Vlasenko

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/