From 562ba1291e72cf4a6c7dbfb918c2cc6821e2eb04 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 31 Jan 2012 20:03:48 -0800 Subject: [PATCH] Stop using placement new like a weirdo --- reader.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/reader.cpp b/reader.cpp index 4a6d8f7ad..8c75eb5b3 100644 --- a/reader.cpp +++ b/reader.cpp @@ -2277,13 +2277,9 @@ static int default_test( wchar_t *b ) void reader_push( const wchar_t *name ) { - // use placement new to guarantee zero initialization :( - void *buff = calloc(1, sizeof(reader_data_t)); - if( !buff ) - { - DIE_MEM(); - } - reader_data_t *n = new(buff) reader_data_t; + // use something nasty which guarantees value initialization (that is, all fields zero) + reader_data_t zerod = {}; + reader_data_t *n = new reader_data_t(zerod); n->app_name = name; n->next = data; @@ -2337,9 +2333,8 @@ void reader_pop() al_destroy( &n->search_prev ); free( (void *)n->token_history_buff); - /* Invoke the destructor to balance our placement new */ - n->~reader_data_t(); - free(n); + /* Invoke the destructor to balance our new */ + delete n; if( data == 0 ) {