delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:to:from:subject:message-id:date:mime-version | |
:content-type; q=dns; s=default; b=jDU23dzfsQ+AGjotmykYxsPaxUDpJ | |
xttfleIPFPF+biubqdO17E5BkrA4M5O6tzRixVA97imbHm+72vJmcfLY+iUWvXkQ | |
D3XB2o/cUB285gxMQnp6efnRhFj6x7ie4zP4OB+2uXazXl7oUvaMRE7mJ0mEom6T | |
F1Vl2dAvH0t/RE= | |
DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:to:from:subject:message-id:date:mime-version | |
:content-type; s=default; bh=pdadtVWRAktJcvFh72dIuUnppoQ=; b=fd0 | |
uomNnf7IgBnvWf+xyXiAr59Fk4QEFC3VfV1TXQ5VJGq65BqwwFrZluIzC15yxm21 | |
OhcsbpOUpcPRFU9Su+H/YjqxcsNsGGnRAIBuua7cpoPbqekiG2V2zh4GeB1JOFoa | |
ieSRF1HarAu+ZGxELWMrI7VYS0X69RqJvotM7efQ= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Virus-Found: | No |
X-Spam-SWARE-Status: | No, score=-3.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1944, EOF, stumbled, camp |
X-HELO: | mx1.redhat.com |
To: | The Cygwin Mailing List <cygwin AT cygwin DOT com> |
From: | Eric Blake <eblake AT redhat DOT com> |
Subject: | SSIZE_MAX bug on 32-bit |
Openpgp: | url=http://people.redhat.com/eblake/eblake.gpg |
Message-ID: | <578658A1.2030201@redhat.com> |
Date: | Wed, 13 Jul 2016 09:05:05 -0600 |
User-Agent: | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
MIME-Version: | 1.0 |
X-IsSubscribed: | yes |
--KUTHShNvtC1F2IsqWCrl1RwJ7L5ouT4NO Content-Type: multipart/mixed; boundary="GASb78bS1s9EAV9j9qcXIwJ181vPBxP1f" From: Eric Blake <eblake AT redhat DOT com> To: The Cygwin Mailing List <cygwin AT cygwin DOT com> Message-ID: <578658A1 DOT 2030201 AT redhat DOT com> Subject: SSIZE_MAX bug on 32-bit --GASb78bS1s9EAV9j9qcXIwJ181vPBxP1f Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I recently stumbled on a glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D13575 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 =3D SIZE_MAX; ssize_t b =3D 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 =3D (0xffffffffU); ssize_t b =3D (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 =3D (0xffffffffffffffffUL); ssize_t b =3D (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=3D2 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=3D] 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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --GASb78bS1s9EAV9j9qcXIwJ181vPBxP1f-- --KUTHShNvtC1F2IsqWCrl1RwJ7L5ouT4NO Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJXhlihAAoJEKeha0olJ0NqlHcH/3Wgs1XtVcpvqwMtiju/ee2V 1Ba2VduupOdmYgpELCDNLDv5MAkN/K9YTf/3VV77ch+Z8cXMyCn+Z+Yow+Br7TT2 tCL0jgapfhuIeP/erIUMLH8MFwkwhODyGb6GLMLoPS0YsZt7bwhfV06dbt7GnrqN 6NDfEK6lL5+Vyqg0M0nUAXWvrmLScjtVcUaJSVqbP+F3r3XlPs3SIjuP5fe9tPeJ oT6ZRtfhHr1AveC54/Iv0M5KopvniziVGf9pvHb4/eYkFkE2z95A5a5scst6Y7Ha wXn9XJlbqM9zT4oEP2TC4SRKfC5Qv3sCq4KwlsaayPdaZr/g78kO0nek8e4DAMY= =k9Re -----END PGP SIGNATURE----- --KUTHShNvtC1F2IsqWCrl1RwJ7L5ouT4NO--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |