From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 3FF333858D39 for ; Wed, 29 Mar 2023 00:08:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FF333858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x32a.google.com with SMTP id d11-20020a05600c3acb00b003ef6e6754c5so4994206wms.5 for ; Tue, 28 Mar 2023 17:08:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680048529; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=dPHKlxPv1UIIvLugLWebLHqxDM4mUAkuzKqiZD2y54c=; b=hTQm+cughKEjpLTaIE2xB0NqLDQB8DNpeeu3mx8INRNS2XeOzPiLvHZKIYHD9fLHKF dUcSC1lzq4Wy+T0+MJzwT1ZAiQpc5D7ziwgSAp4zYnWsOZisig+YUURUhBsGSVktpxS3 HAgN4xc+rjOe5Jd3ne44hQpPrRhnhGYUgQMDYjikfvOIUek4ap2n2cfoao3G91gxFS4W Rm5BcxS+D44fN9H5ItZE+xuOBFPzNzpy2jIj9yAD7tp0AbXfi/OYnmHUcJ1tXib/luOm T1P6M4lABb9eGZCecsSqaXqxflTWXL6FvYI7nqvBHFo8VhikDIH1Iqsd+tjizPkXjW6y OW+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680048529; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=dPHKlxPv1UIIvLugLWebLHqxDM4mUAkuzKqiZD2y54c=; b=t3wZmi9p3jZjsJvRVZpBi0Wf0obFpPJvRj1L2bdaRyeL5/g+yCjO9bXlmRFSIcs4z/ OvIqgxvUwkOoWdTIGDjfUlzUBzGrzfT7mL26i88C0S4Mwo8YCHZosoG/D0gFLmwfiX5u 9thZWRM2p0m8NWnhdByQ0K4lY55+OdjHPe+CSERwkb2ajJBb16t4YrHuG+NqIGRRZk5y iYZYzbTCd3WEXquUx3bIn0h1gH/Pmanck3ZXRWnAy5Os1lyxrbpVjMySaLyN4DV7UGTR LGtfr85cScqhGwONZNmXKM+m//9Ufy0PHFGE7iSDm+t0xRkM3e6/10Ge9miehn9BJqhv QATw== X-Gm-Message-State: AO0yUKXtW/jSHOLd/vcsfTaWXEeZRqaq2ynEwkzY0CrW1LtzDvq2+EYF lNOE/mRh/Tmo+i6Mo4m5JoXF/Wj4qbo= X-Google-Smtp-Source: AK7set8a+GuTOQSwAzF5KHb1tV+xs4lHwzJXHwE+KW0DZucyBeYDiPsJ7ZD/cjmm4VM+ulEyC7LMVg== X-Received: by 2002:a05:600c:2312:b0:3eb:39e2:915b with SMTP id 18-20020a05600c231200b003eb39e2915bmr13381163wmo.31.1680048528541; Tue, 28 Mar 2023 17:08:48 -0700 (PDT) Received: from [192.168.0.160] ([170.253.51.134]) by smtp.gmail.com with ESMTPSA id p2-20020a05600c204200b003ed2c0a0f37sm271780wmg.35.2023.03.28.17.08.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 28 Mar 2023 17:08:48 -0700 (PDT) Message-ID: <4e573abd-9ba0-e483-ab48-84e9ea98f90a@gmail.com> Date: Wed, 29 Mar 2023 02:08:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: Bad interaction between signal constants and -Wsign-conversion Content-Language: en-US To: Zack Weinberg , GNU libc development References: <280b4afe-d080-4be5-a296-ec914b0b5439@app.fastmail.com> From: Alejandro Colomar In-Reply-To: <280b4afe-d080-4be5-a296-ec914b0b5439@app.fastmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------u32ovr690h70XYXrcQZflLHq" X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------u32ovr690h70XYXrcQZflLHq Content-Type: multipart/mixed; boundary="------------39bsnP8tHsmI5101gQIuAHdH"; protected-headers="v1" From: Alejandro Colomar To: Zack Weinberg , GNU libc development Message-ID: <4e573abd-9ba0-e483-ab48-84e9ea98f90a@gmail.com> Subject: Re: Bad interaction between signal constants and -Wsign-conversion References: <280b4afe-d080-4be5-a296-ec914b0b5439@app.fastmail.com> In-Reply-To: <280b4afe-d080-4be5-a296-ec914b0b5439@app.fastmail.com> --------------39bsnP8tHsmI5101gQIuAHdH Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Zack, On 3/28/23 03:23, Zack Weinberg via Libc-alpha wrote: > This test program does something perfectly normal. Well, it's cut down= > from a program that does something perfectly normal. SA_RESETHAND is > one of the bit flags intended to be used with the sa_flags field of > struct sigaction. >=20 > #include >=20 > struct sigaction sa =3D {=20 > .sa_flags =3D SA_RESETHAND, > }; >=20 > However ... on Linux, SA_RESETHAND happens to have the value 0x80000000= , > and therefore, the type of that constant is 'unsigned int'. And the > type of sa_flags is 'int'. So if you compile this test program with > -Wconversion you get a warning: >=20 > $ gcc -fsyntax-only -Wconversion test.c > test.c:4:15: warning: signed conversion from =E2=80=98unsigned int=E2=80= =99 to =E2=80=98int=E2=80=99 > changes value from =E2=80=982147483648=E2=80=99 to =E2=80=98-2147483= 648=E2=80=99 [-Wsign-conversion] > 4 | .sa_flags =3D SA_RESETHAND, > | ^~~~~~~~~~~~ >=20 > This strikes me as a (minor) bug in our headers. Given the ABI constra= ints > (this is a flags word passed to the kernel), I think the most straightf= orward > fix is probably to change the #define in bits/sigaction.h to >=20 > # define SA_RESETHAND ((int)0x80000000) /* Reset to SIG_DFL on entry to= handler. */ >=20 > Anyone got a better idea? Well, probably not doable now, but is switching to the unsigned counterpa= rt still possible now? It would require investigating how this member is being used out there, to know if we're going to break anyones code, and integer conversions are very tricky, so it's hard to know, but for a flag= s field that is to be used in bitwise operations, I don't expect anyone to actually use it as an int, but rather as an unsigned that for historic reasons happens to be signed. This is also a reminder that new such fields in structures and function parameters should always be of unsigned types if they're going to hold flags (or in general, if they're to be treated as something that requires= bitwise operations). Cheers, Alex >=20 > zw --=20 GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5 --------------39bsnP8tHsmI5101gQIuAHdH-- --------------u32ovr690h70XYXrcQZflLHq Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmQjgYcACgkQnowa+77/ 2zKgjhAAp/T6QKZ2TzSJnEs4T+VHkGsCcpxo4SLbCLSo+MVZ6IY3Eo0s4ufTbmhB azvQtZaLms17bC+0SvCZWwSvfebZT6NLVX9iQi848+TzdC9U2RHnsMzKFhpPTP4z e8RoGzs855jl4Pa4bLA/3pDQzCh8qKmWODU+QSFS0+kR03LcOncG9dMV3vPIFWH+ kxSfxyThW0veUJo/eJplJsN3wwamT1vlbdLcCVMjS+AJQFH94061gjkDOb9pjG7P sYGO6pJExo3mqBZcavSsQ6zOyUv7pGF+Vzie7I8P6wFxb9CxqZ8THsouLURrHuOK MW0dLNqyQ6oU9sydxK2FswLPfXHiWpc3AlbytvS9Zq3+f1rcMbh8shrzLenI10+A yg5xpfW+ulGjMQt95B5TogwL5YJbBppzZiWsQvDCDQVtCWhpeO0cGl2uG8LFfPTL 7YdQ9J4yv9oS6ZxB9e5naIoBRZwl2Zk+wYFE7YMtIXp3d+psmoj++7pYKGnNtBFs CUVWx1zhYLWpBGfh7LoLniATItxzUh3SjKRoI6FO6PLa3Rx+tn59VYHOXW/GhQ/V CKFlXGS0dFQ/JRF5IWVliif3RbDhIYThu7UTLVjbFD2NV8ZVB69Sb77Q8ODQQXOu 6N/4e4c+qOfQn1FTPbF/nFklPyansOnXFgrYMWN/OGZq6KyMMsQ= =tJd1 -----END PGP SIGNATURE----- --------------u32ovr690h70XYXrcQZflLHq--