public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/13575] New: SSIZE_MAX defined as LONG_MAX is inconsistent with SIZE_MAX, when __WORDSIZE != 64
@ 2012-01-09 11:19 soltys at ziu dot info
  2012-01-09 11:57 ` [Bug libc/13575] " joseph at codesourcery dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: soltys at ziu dot info @ 2012-01-09 11:19 UTC (permalink / raw)
  To: glibc-bugs

http://sourceware.org/bugzilla/show_bug.cgi?id=13575

             Bug #: 13575
           Summary: SSIZE_MAX defined as LONG_MAX is inconsistent with
                    SIZE_MAX, when __WORDSIZE != 64
           Product: glibc
           Version: 2.15
            Status: NEW
          Severity: minor
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: soltys@ziu.info
    Classification: Unclassified


long <type> has always higher rank than <type> even if both have the same
representation. When __WORDSIZE is not 64, SIZE_MAX uses (unsigned int) type in
constant explicitly, but SSIZE_MAX falls back to LONG_MAX which is (long int) -
which is different (higher) rank than (int) or (unsigned int).

Consider following example on 32bit architectures:

#define  _POSIX_SOURCE 1
#include <stdio.h>
#include <limits.h>
#include <sys/types.h>

int main(void)
{
        ssize_t x = 10;
        printf("val: %zd\n", SSIZE_MAX - x);
        return 0;
}

if compiled with gcc -Wall test.c
The compiler will issue warning:

test.c:9: warning: format ‘%zd’ expects type ‘signed size_t’, but argument 2
has type ‘long int’

So - when __WORDSIZE is not 64 - shouldn't SSIZE_MAX be defined as INT_MAX to
be consistent with SIZE_MAX (the change also fixes warning in the above case) ?

The problem doesn't happen when __WORDSIZE == 64, as in such case types are
(unsigned long int) and (long int) for SIZE_MAX and SSIZE_MAX respectively.

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-06-27 11:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-09 11:19 [Bug libc/13575] New: SSIZE_MAX defined as LONG_MAX is inconsistent with SIZE_MAX, when __WORDSIZE != 64 soltys at ziu dot info
2012-01-09 11:57 ` [Bug libc/13575] " joseph at codesourcery dot com
2012-01-09 18:45 ` drepper.fsp at gmail dot com
2012-01-10  1:29 ` soltys at ziu dot info
2014-06-27 11:14 ` fweimer 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).