From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id AD69E386F463 for ; Sat, 25 Apr 2020 21:23:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AD69E386F463 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-kpg9mgW1O5qSECfR7lR9Ig-1; Sat, 25 Apr 2020 17:23:16 -0400 X-MC-Unique: kpg9mgW1O5qSECfR7lR9Ig-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 546C21800D4A; Sat, 25 Apr 2020 21:23:15 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-52.phx2.redhat.com [10.3.112.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 251DE60609; Sat, 25 Apr 2020 21:23:14 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.14.7/8.14.7) with ESMTP id 03PLNDsp025289; Sat, 25 Apr 2020 17:23:13 -0400 From: DJ Delorie To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: Re: [patch] Use unsigned constants for ICMP6 filters [BZ #22489] In-Reply-To: <87imhnihh0.fsf@igel.home> (message from Andreas Schwab on Sat, 25 Apr 2020 19:48:59 +0200) Date: Sat, 25 Apr 2020 17:23:13 -0400 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Apr 2020 21:23:20 -0000 Andreas Schwab writes: >> GCC complains that -65 doesn't fit in "uint32_t" and was converted to >> (unsigned) 0xffffffbf. > > -65 fits very well in uint32_t, this is a perfectly defined operation. > The bug is an undefined shift (which can produce an arbitrary value). The left shift is limited to "1" shifted by 0..31 bits, which is well defined. A shift of 31 bits doesn't result in a warning, either, because the resulting ~bit pattern indicates a positive value. The right shift might produce an array overflow, but that would happen even for unsigned values, and the warning happens for constants that are known to fit. GCC indicates the warning is with the &=3D operator: $ gcc -c -Wsign-conversion icmp6_test.c icmp6_test.c: In function =E2=80=98main=E2=80=99: icmp6_test.c:14:7: warning: unsigned conversion from =E2=80=98int=E2=80=99 = to =E2=80=98uint32_t=E2=80=99 {aka =E2=80=98unsigned int=E2=80=99} changes = value from =E2=80=98-65=E2=80=99 to =E2=80=984294967231=E2=80=99 [-Wsign-co= nversion] 14 | &=3D ~(1 << | ^~ #include = =20 #include = =20 #undef ICMP6_FILTER_SETPASS #define ICMP6_FILTER_SETPASS(type, filterp) \ ((((filterp)->icmp6_filt[(type) >> 5]) &=3D ~(1 << ((type) & 31)))) = =20 int main() = =20 { = =20 struct icmp6_filter filter; = =20 = =20 (((filter.icmp6_filt[(134) >> 5]) &=3D ~(1 << =09 ((134) & 31)))); = =20 return EXIT_SUCCESS; = =20 }