This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove


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<T>::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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]