public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: Benjamin De Kosnik <bkoz@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [wwwdocs] gcc-4.8/porting_to.html
Date: Thu, 14 Mar 2013 11:21:00 -0000	[thread overview]
Message-ID: <20130314112132.GC12913@tucnak.redhat.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1303141447390.26066@monopod.intra.ispras.ru>

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

  reply	other threads:[~2013-03-14 11:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-13  9:29 Benjamin De Kosnik
2013-03-13 10:01 ` Tobias Burnus
2013-03-14  0:28   ` Benjamin De Kosnik
2013-03-14  1:23     ` Benjamin De Kosnik
2013-03-14 11:10     ` Alexander Monakov
2013-03-14 11:21       ` Jakub Jelinek [this message]
2013-03-13 10:27 ` Mikael Pettersson
2013-03-13 10:37   ` Alexander Monakov
2013-03-13 10:51     ` Mikael Pettersson
2013-03-14  0:26     ` Benjamin De Kosnik
2015-04-12 11:02 ` Gerald Pfeifer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130314112132.GC12913@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=amonakov@ispras.ru \
    --cc=bkoz@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).