From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2076 invoked by alias); 14 Mar 2013 11:21:45 -0000 Received: (qmail 2068 invoked by uid 22791); 14 Mar 2013 11:21:44 -0000 X-SWARE-Spam-Status: No, hits=-7.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_CP X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 14 Mar 2013 11:21:37 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2EBLag8029311 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 14 Mar 2013 07:21:37 -0400 Received: from zalov.cz (vpn1-4-156.ams2.redhat.com [10.36.4.156]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2EBLYfq027033 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 14 Mar 2013 07:21:36 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r2EBLXDE000498; Thu, 14 Mar 2013 12:21:33 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r2EBLW7G000497; Thu, 14 Mar 2013 12:21:32 +0100 Date: Thu, 14 Mar 2013 11:21:00 -0000 From: Jakub Jelinek To: Alexander Monakov Cc: Benjamin De Kosnik , gcc-patches@gcc.gnu.org Subject: Re: [wwwdocs] gcc-4.8/porting_to.html Message-ID: <20130314112132.GC12913@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20130313022916.0728c82e@oakwood> <51404E84.3070903@net-b.de> <20130313172850.49f4b3d7@oakwood> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg00499.txt.bz2 On Thu, Mar 14, 2013 at 03:07:36PM +0400, Alexander Monakov wrote: > > It still references memcpy in -Wsizeof-pointer-memaccess section. Let me > suggest instead: > > To fix, properly pass the size of cleared memory as the last argument: > either dereference the pointer argument to sizeof when clearing *one > pointed-to element*, or in addition to that multiply sizeof(*p) by the > number of elements to clear in the pointed-to array (which may not be > known at the point of memset call without additional code changes). > > > > I suppose a good chunk of problematic code hitting this warning would be doing > something like: > > void foo(int a[]) > { > memset(a, 0, sizeof(a)); > } > > ... in which case dereferencing a in sizeof is probably the wrong thing to do. The has different wording for the different cases, can suggest you to 1) remove addressof 2) provide an explicit length 3) dereference it E.g. 1) is for cases like memset (&a, 0, sizeof (&a)); where removing the & is usually the right thing to do. Jakub