Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/5] Poison non-POD memset & non-trivially-copyable  memcpy/memmove
Date: Thu, 20 Apr 2017 03:27:00 -0000	[thread overview]
Message-ID: <44b612a2b2dadc142c054a1967dc2600@polymtl.ca> (raw)
In-Reply-To: <1492050475-9238-2-git-send-email-palves@redhat.com>

On 2017-04-12 22:27, Pedro Alves wrote:
> This patch catches invalid initialization of non-POD types with
> memset, at compile time.
> 
> This is what I used to catch the problems fixed by the rest of the
> series:
> 
>   $ make -k 2>&1 | grep "deleted function"
>   src/gdb/breakpoint.c:951:53: error: use of deleted function ‘void*
> memset(T*, int, size_t) [with T = bp_location;
> <template-parameter-1-2> = void; size_t = long unsigned int]’
>   src/gdb/breakpoint.c:7325:32: error: use of deleted function ‘void*
> memset(T*, int, size_t) [with T = bp_location;
> <template-parameter-1-2> = void; size_t = long unsigned int]’
>   src/gdb/btrace.c:1153:42: error: use of deleted function ‘void*
> memset(T*, int, size_t) [with T = btrace_insn;
> <template-parameter-1-2> = void; size_t = long unsigned int]’
> 
> I'll move this to the end of the series before pushing (if agreed).
> 
> (I've posted another series recently that adds some of the same traits
> bits to common/traits.h.  They're really useful.)

That's really nice.  I'm actually surprised we didn't get random crashes 
because of that yet!

> diff --git a/gdb/common/poison.h b/gdb/common/poison.h
> new file mode 100644
> index 0000000..57a1733
> --- /dev/null
> +++ b/gdb/common/poison.h
> @@ -0,0 +1,83 @@
> +/* Poison symbols at compile time.
> +
> +   Copyright (C) 2017 Free Software Foundation, Inc.
> +
> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it and/or 
> modify
> +   it under the terms of the GNU General Public License as published 
> by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see 
> <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef COMMON_POISON_H
> +#define COMMON_POISON_H
> +
> +#include "traits.h"
> +
> +/* Poison memset of non-POD types.  The idea is catching invalid
> +   initialization of non-POD structs that is easy to be introduced as
> +   side effect of refactoring.  For example, say this:
> +
> + struct S { VEC(foo_s) *m_data; };
> +
> +is converted to this at some point:
> +
> + struct S {
> +   S() { m_data.reserve (10); }
> +   std::vector<foo> m_data;
> + };

Here it says struct S ...

> +
> +and old code was initializing B objects like this:
> +
> + struct B b;
> + memset (&b, 0, sizeof (B)); // whoops, now wipes vector.

... and here struct B?

Simon


  reply	other threads:[~2017-04-20  3:27 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13  2:27 [PATCH 0/4] " Pedro Alves
2017-04-13  2:28 ` [PATCH 3/5] Don't memset non-POD types: struct bp_location Pedro Alves
2017-04-13  2:28 ` [PATCH 4/5] Don't memset non-POD types: struct btrace_insn Pedro Alves
2017-04-13  7:57   ` Metzger, Markus T
2017-04-25  1:11     ` Pedro Alves
2017-04-13  2:28 ` [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove Pedro Alves
2017-04-20  3:27   ` Simon Marchi [this message]
2017-04-25  1:14     ` Pedro Alves
2017-04-25  1:19       ` Pedro Alves
2017-04-25  8:24       ` Yao Qi
2017-04-25  9:24         ` Pedro Alves
2017-04-25 10:02           ` Pedro Alves
2017-04-24  1:12   ` Simon Marchi
2017-04-24  1:53     ` Simon Marchi
2017-04-27 13:58       ` Pedro Alves
2017-04-30  1:51         ` Simon Marchi
2017-05-17 11:35           ` Pedro Alves
2017-05-17 13:11             ` Simon Marchi
2017-05-17 13:20               ` Pedro Alves
2017-04-27 13:57     ` Pedro Alves
2017-04-13  2:28 ` [PATCH 2/5] Don't memcpy non-trivially-copyable types: Make enum_flags triv. copyable Pedro Alves
2017-04-20  3:34   ` Simon Marchi
2017-04-25  1:10     ` Pedro Alves
2017-04-13  2:35 ` [PATCH 5/5] Don't memset non-POD types: struct breakpoint Pedro Alves
2017-04-20  4:00   ` Simon Marchi
2017-04-25  1:11     ` Pedro Alves

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=44b612a2b2dadc142c054a1967dc2600@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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