This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
gethostid() output sign-extended on 64-bit platforms
- From: Greg Edwards <edwardsg at sgi dot com>
- To: glibc-bugs at sources dot redhat dot com
- Date: Wed, 15 Jun 2005 11:30:32 -0500
- Subject: gethostid() output sign-extended on 64-bit platforms
There is a signed int to signed long bug in gethostid() for 64-bit
platforms. If the 31st bit of the hostid is a 1, it gets signed
extended to 64 bits. It should instead be cast as an unsigned int on
return. Example:
# hostid
ffffffffa2802df3
With the attached patch, it returns to the expected output:
# hostid
a2802df3
Signed-off-by: Greg Edwards <edwardsg@sgi.com>
---
sysdeps/unix/sysv/linux/gethostid.c | 2 +-
1 files changed, 1 insertion(+), 1 deletion(-)
Index: libc/sysdeps/unix/sysv/linux/gethostid.c
===================================================================
--- libc.orig/sysdeps/unix/sysv/linux/gethostid.c 2004-12-15 22:12:57.000000000 -0600
+++ libc/sysdeps/unix/sysv/linux/gethostid.c 2005-06-15 11:23:32.496024451 -0500
@@ -118,6 +118,6 @@ gethostid ()
/* For the return value to be not exactly the IP address we do some
bit fiddling. */
- return (int32_t) (in.s_addr << 16 | in.s_addr >> 16);
+ return (uint32_t) (in.s_addr << 16 | in.s_addr >> 16);
}
#endif