From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2801 invoked by alias); 24 Apr 2017 01:53:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 2608 invoked by uid 89); 24 Apr 2017 01:53:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Apr 2017 01:53:02 +0000 Received: by simark.ca (Postfix, from userid 33) id 2FD291E4A4; Sun, 23 Apr 2017 21:53:03 -0400 (EDT) To: Pedro Alves Subject: Re: [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 24 Apr 2017 01:53:00 -0000 From: Simon Marchi Cc: gdb-patches@sourceware.org In-Reply-To: References: <1492050475-9238-1-git-send-email-palves@redhat.com> <1492050475-9238-2-git-send-email-palves@redhat.com> Message-ID: <9ee5551a7999a72a0040f15e6e5410a1@polymtl.ca> X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.2.4 X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00632.txt.bz2 On 2017-04-23 21:12, Simon Marchi wrote: > On 2017-04-12 22:27, Pedro Alves wrote: >> This patch catches invalid initialization of non-POD types with >> memset, at compile time. > > Would it be possible to do something similar but to catch uses of > XNEW/XCNEW with types that need new? XNEW is defined as: > > #define XNEW(T) ((T *) xmalloc (sizeof (T))) > > I just tried this, and it seems to work well: > > #define assert_pod(T) static_assert(std::is_pod::value) > > #undef XNEW > #define XNEW(T) ({ assert_pod(T); (T *) xmalloc (sizeof (T)); }) > #undef XCNEW > #define XCNEW(T) ({ assert_pod(T); (T *) xcalloc (1, sizeof (T)); }) > > assuming the compiler knows about statement expressions. Actually, it should probably use std::is_trivially_constructible. And I suppose we could do the same with xfree, delete it when !std::is_trivially_destructible.