This is the mail archive of the glibc-bugs@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/1017] New: gethostid should not sign-extend ids on 64-bit hosts


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]