* SSIZE_MAX bug on 32-bit
@ 2016-07-13 15:05 Eric Blake
2016-07-13 15:41 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: Eric Blake @ 2016-07-13 15:05 UTC (permalink / raw)
To: The Cygwin Mailing List
[-- Attachment #1.1: Type: text/plain, Size: 1995 bytes --]
I recently stumbled on a glibc bug:
https://sourceware.org/bugzilla/show_bug.cgi?id=13575
and note that cygwin has the same bug in 32 bit.
test case 1:
$ cat <<\EOF | gcc -E -P - | grep size_t
#include <stdint.h>
#include <sys/types.h>
#include <limits.h>
size_t a = SIZE_MAX; ssize_t b = SSIZE_MAX;
EOF
On 32-bit, we see that both types are based on int:
typedef unsigned int size_t;
typedef signed int _ssize_t;
typedef _ssize_t ssize_t;
but that the constant for SSIZE_MAX is based on long
size_t a = (0xffffffffU); ssize_t b = (0x7fffffffL);
On 64-bit, we see that both types are based on long, as are the constants:
typedef long unsigned int size_t;
typedef long signed int _ssize_t;
typedef _ssize_t ssize_t;
size_t a = (0xffffffffffffffffUL); ssize_t b = (0x7fffffffffffffffL);
which is correct.
test case 2:
$ cat foo.c
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <limits.h>
int main(void) {
printf("%zu %zd\n", SIZE_MAX, SSIZE_MAX);
return 0;
}
$ gcc -o foo -Wall -Wformat=2 foo.c
Technically, there is NO portable way to pass ssize_t to printf without
a cast (the standards do not guarantee that %zd is ssize_t, because
ssize_t can be a different rank type than size_t) - but in practice,
most platforms use the same rank for the two types (both glibc and
Cygwin fall into this camp). Therefore, this should compile without
warning; 64-bit is fine, but 32-bit gripes:
foo.c: In function 'main':
foo.c:6:10: warning: format '%zd' expects argument of type 'signed
size_t', but argument 3 has type 'long int' [-Wformat=]
Also, recall that both SIZE_MAX and SSIZE_MAX must be usable in #if
expressions, so we can't use a cast to size_t in the macro, but instead
have to expand directly to an expression with the right type.
I'll probably try my hand at a patch later today.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: SSIZE_MAX bug on 32-bit
2016-07-13 15:05 SSIZE_MAX bug on 32-bit Eric Blake
@ 2016-07-13 15:41 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2016-07-13 15:41 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 452 bytes --]
On Jul 13 09:05, Eric Blake wrote:
> I recently stumbled on a glibc bug:
> https://sourceware.org/bugzilla/show_bug.cgi?id=13575
>
> and note that cygwin has the same bug in 32 bit.
> [...]
> I'll probably try my hand at a patch later today.
I'm looking forward to it.
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-13 15:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-13 15:05 SSIZE_MAX bug on 32-bit Eric Blake
2016-07-13 15:41 ` Corinna Vinschen
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).