Subject: lib/14485: libc code portability (???) problem
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kre@munnari.OZ.AU>
List: netbsd-bugs
Date: 11/06/2001 21:09:45
>Number: 14485
>Category: lib
>Synopsis: libc code portability (!?!) problem
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Nov 06 06:09:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Robert Elz
>Release: NetBSD-current 20011105
>Organization:
University of Melbourne
>Environment:
System: NetBSD brandenburg.cs.mu.OZ.AU 1.5_BETA NetBSD 1.5_BETA (BRANDENBURG) #6: Sun Oct 14 19:40:40 ICT 2001 kre@brandenburg.cs.mu.OZ.AU:/usr/src/sys/arch/i386/compile/BRANDENBURG i386
Really...
NetBSD munnnari.cs.mu.OZ.AU 1.5R NetBSD 1.5R (MUNNNARI) #0: Thu Feb 15 16:25:51 EST 2001 kre@lavender.cs.mu.OZ.AU:/extra/Sys/arch/alpha/compile/MUNNNARI alpha
>Description:
Meaningless stupid compiler warnings keep libc from building
on an alpha (using i386 target).
>How-To-Repeat:
On alpha (probably any other LP64):
cd /usr/src
./build.sh -m i386 (other options to set directories).
Wait a while, then ...
CC="/usr/tools/bin/i386--netbsdelf-gcc" /usr/tools/bin/i386--netbsdelf-lint -chapbxzF -w -X 272 -d /home/trees/i386/usr/include -D_LIBC -DNLS -DYP -DHESIOD -DLIBC_SCCS -DSYSLIBC_SCCS -D_REENTRANT -I/usr/src/lib/libc/include -DINET6 -D__DBINTERFACE_PRIVATE -I/usr/src/lib/libc/../../libexec/ld.elf_so -I/usr/src/lib/libc/dlfcn -DWITH_RUNE -DRUNEMOD_MAJOR=3 -D_PATH_LOCALEMODULE=\"/usr/lib/runemodule\" -DRESOLVSORT -I. -DPOSIX_MISTAKE -DPORTMAP -DFLOATING_POINT -i /usr/src/lib/libc/net/inet_neta.c
/usr/src/lib/libc/net/inet_neta.c(72): warning: extra bits set to 0 in conversion of 'unsigned int' to 'unsigned long', op & [309]
/usr/src/lib/libc/net/inet_neta.c(73): warning: extra bits set to 0 in conversion of 'unsigned int' to 'unsigned long', op & [309]
The same thing happens in inet_netof.c, and in ../gen/nlist_aout.c
The problem is code of the form
u_long var;
var & 0xFF000000 (the value varies)
The 0xFF000000 is what the compiler (for inexplicable reasons) is
complaining about. Since var is u_long, the const needs to be promoted
to be u_long as well, so just do that explicitly.
>Fix:
You probably don't want this patch, there is sure to be a more
elegant way, but it does work...
No patch (yet) for nlist_aout.c - I think the real bug there is
that the (contents of) the file is being compiled at all, though
installing a similar fix in the definitions of the N_BADMAG and
N_SYMOFF macros is probably the right thing to do, so compiling
for platforms that really are a.out will work.
--- inet_neta.c.ORIG Sun Jan 23 09:19:15 2000
+++ inet_neta.c Wed Nov 7 00:57:11 2001
@@ -67,12 +67,12 @@
char *odst = dst;
char *tp;
_DIAGASSERT(dst != NULL);
- while (src & 0xffffffff) {
- u_char b = (u_char)((src & 0xff000000) >> 24);
+ while (src & (u_long)0xffffffff) {
+ u_char b = (u_char)((src & (u_long)0xff000000) >> 24);
src <<= 8;
if (b) {
if (size < sizeof "255.")
goto emsgsize;
--- inet_netof.c.ORIG Sun Jan 23 09:19:15 2000
+++ inet_netof.c Wed Nov 7 00:50:37 2001
@@ -60,11 +60,11 @@
struct in_addr in;
{
register u_long i = ntohl(in.s_addr);
if (IN_CLASSA(i))
- return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+ return (((i)&(u_long)IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
else if (IN_CLASSB(i))
- return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+ return (((i)&(u_long)IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
else
- return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+ return (((i)&(u_long)IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
}
>Release-Note:
>Audit-Trail:
>Unformatted: