Stop using placement new like a weirdo

This commit is contained in:
ridiculousfish 2012-01-31 20:03:48 -08:00
parent 3adf6d25f6
commit 562ba1291e

View file

@ -2277,13 +2277,9 @@ static int default_test( wchar_t *b )
void reader_push( const wchar_t *name ) void reader_push( const wchar_t *name )
{ {
// use placement new to guarantee zero initialization :( // use something nasty which guarantees value initialization (that is, all fields zero)
void *buff = calloc(1, sizeof(reader_data_t)); reader_data_t zerod = {};
if( !buff ) reader_data_t *n = new reader_data_t(zerod);
{
DIE_MEM();
}
reader_data_t *n = new(buff) reader_data_t;
n->app_name = name; n->app_name = name;
n->next = data; n->next = data;
@ -2337,9 +2333,8 @@ void reader_pop()
al_destroy( &n->search_prev ); al_destroy( &n->search_prev );
free( (void *)n->token_history_buff); free( (void *)n->token_history_buff);
/* Invoke the destructor to balance our placement new */ /* Invoke the destructor to balance our new */
n->~reader_data_t(); delete n;
free(n);
if( data == 0 ) if( data == 0 )
{ {