public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/1017] New: gethostid should not sign-extend ids on 64-bit hosts
@ 2005-06-16 22:42 eggert at gnu dot org
2005-06-16 22:44 ` [Bug libc/1017] " eggert at gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: eggert at gnu dot org @ 2005-06-16 22:42 UTC (permalink / raw)
To: glibc-bugs
I'm following up to Tim Waugh's bug report today on bug-coreutils@gnu.org:
The gethostid() function returns a long int, and on 64-bit platforms
this can mean that the 32-bit value becomes sign-extended. Here is a
patch to only display the 32-bit value in hostid().
Original bug report:
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=160078
Here's the underlying problem. The program:
#include <unistd.h>
#include <stdio.h>
int main (void) { printf ("%lx", gethostid ()); }
prints something like "80b05874" on a 64-bit Solaris host, but
"ffffffff80b05874" on a 64-bit GNU/Linux host.
This is because glibc is incompatible with Solaris on 64-bit hosts.
glibc sign-extends the 32-bit host ID, whereas Solaris does not.
POSIX <http://www.opengroup.org/onlinepubs/009695399/functions/gethostid.html>
says merely that the host ID must be a "32-bit identifier". One could
argue that a number in the range -2147483648...2147483647 is a "32-bit
identifier" and therefore glibc conforms, but the Solaris
interpretation is more natural, and is less likely to break existing
code as illustrated in the above-referenced bug report and the
above-mentioned example.
I'll attach a proposed patch.
--
Summary: gethostid should not sign-extend ids on 64-bit hosts
Product: glibc
Version: 2.3.5
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: gotom at debian dot or dot jp
ReportedBy: eggert at gnu dot org
CC: glibc-bugs at sources dot redhat dot com
GCC host triplet: 64-bit linux
http://sources.redhat.com/bugzilla/show_bug.cgi?id=1017
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/1017] gethostid should not sign-extend ids on 64-bit hosts
2005-06-16 22:42 [Bug libc/1017] New: gethostid should not sign-extend ids on 64-bit hosts eggert at gnu dot org
@ 2005-06-16 22:44 ` eggert at gnu dot org
2005-06-16 22:51 ` jakub at redhat dot com
2005-09-22 17:25 ` drepper at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: eggert at gnu dot org @ 2005-06-16 22:44 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From eggert at gnu dot org 2005-06-16 22:44 -------
Created an attachment (id=519)
--> (http://sources.redhat.com/bugzilla/attachment.cgi?id=519&action=view)
patch for gethostid 64-bit sign extension compatibility problem
--
http://sources.redhat.com/bugzilla/show_bug.cgi?id=1017
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/1017] gethostid should not sign-extend ids on 64-bit hosts
2005-06-16 22:42 [Bug libc/1017] New: gethostid should not sign-extend ids on 64-bit hosts eggert at gnu dot org
2005-06-16 22:44 ` [Bug libc/1017] " eggert at gnu dot org
@ 2005-06-16 22:51 ` jakub at redhat dot com
2005-09-22 17:25 ` drepper at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: jakub at redhat dot com @ 2005-06-16 22:51 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From jakub at redhat dot com 2005-06-16 22:51 -------
I disagree. If you don't sign extend, then gethostid () on the same system
may return different id between 32-bit and 64-bit programs (for 32-bit
program it returns some negative value, for 64-bit program 2^32 bigger value).
When hostid(1) wants to print a signed value where only low 32 bits are
supposed to have the actual id as hexadecimal value (i.e. unsigned), it should
mask out all bits but the low 32.
--
http://sources.redhat.com/bugzilla/show_bug.cgi?id=1017
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/1017] gethostid should not sign-extend ids on 64-bit hosts
2005-06-16 22:42 [Bug libc/1017] New: gethostid should not sign-extend ids on 64-bit hosts eggert at gnu dot org
2005-06-16 22:44 ` [Bug libc/1017] " eggert at gnu dot org
2005-06-16 22:51 ` jakub at redhat dot com
@ 2005-09-22 17:25 ` drepper at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: drepper at redhat dot com @ 2005-09-22 17:25 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From drepper at redhat dot com 2005-09-22 17:25 -------
The code as it is now is correct. Sign extension is necessary. If you want to
complain, track down the person who starting using a signed value for such an
obvious unsigned use case.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |WONTFIX
http://sourceware.org/bugzilla/show_bug.cgi?id=1017
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-09-22 17:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-16 22:42 [Bug libc/1017] New: gethostid should not sign-extend ids on 64-bit hosts eggert at gnu dot org
2005-06-16 22:44 ` [Bug libc/1017] " eggert at gnu dot org
2005-06-16 22:51 ` jakub at redhat dot com
2005-09-22 17:25 ` drepper at redhat dot com
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).