public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* gethostid() output sign-extended on 64-bit platforms
@ 2005-06-15 16:30 Greg Edwards
0 siblings, 0 replies; only message in thread
From: Greg Edwards @ 2005-06-15 16:30 UTC (permalink / raw)
To: glibc-bugs
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-06-15 16:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-15 16:30 gethostid() output sign-extended on 64-bit platforms Greg Edwards
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).