pike.git / src / modules / _Stdio / buffer.cmod

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:272:    memmove( io->buffer, io_read_pointer(io), io_len(io) );    io->num_move++;    io->len -= io->offset;    io->offset = 0;    }    }       if( UNLIKELY(io->len + bytes > io->allocated) )    {    size_t new_len = io->allocated; +  void *new_ptr;       do    new_len = ((new_len+32)*2)-32;    while( new_len < io->len + bytes );    -  io->buffer = xrealloc( io->buffer, new_len ); +  new_ptr = xrealloc( io->buffer, bytes ); +  if( !new_ptr ) +  Pike_error(msg_out_of_mem_2, bytes ); +  io->buffer = new_ptr;    io->num_malloc++;    io->allocated = new_len;    }    return io->buffer+io->len;    }       static unsigned char *io_add_space( Buffer *io, size_t bytes, int force )    {    if( io->len == io->offset )    io->offset = io->len = 0;
pike.git/src/modules/_Stdio/buffer.cmod:2067:    *! Note that calling this function excessively will slow things    *! down, since the data often has to be copied.    *!    *! @note    *! This function could possibly throw an out-of-memory error    *! if the realloc fails to find a new (smaller) memory area.    */    PIKEFUN void trim( )    {    Buffer *io = THIS; +  void *new_ptr; +     io_add_space( io, 0, 1 );    if( io->allocated > io->len+32 )    { -  io->buffer = xrealloc( io->buffer, io->len ); +  new_ptr = xrealloc( io->buffer, io->len ); +  if (new_ptr) +  Pike_error(msg_out_of_mem_2, io->len); +  io->buffer = new_ptr;    io->num_malloc++;    io->allocated = io->len;    }    }       /*! @decl int(0..)|int(-1..-1) consume( int(0..) n )    *!    *! Discard the first @[n] bytes from the buffer    *!    *! Returns -1 on error and the amount of space still left otherwise.