mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Stop using placement new like a weirdo
This commit is contained in:
parent
3adf6d25f6
commit
562ba1291e
1 changed files with 5 additions and 10 deletions
15
reader.cpp
15
reader.cpp
|
@ -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 )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue