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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:200:    {    io->stash.ptr = io->buffer;    io->stash.len = io->allocated;    io->malloced = 0;    io->buffer = 0;    io->offset = 0;    io->len = 0;    }    }    -  static void io_ensure_malloced( Buffer *io, int bytes ) +  static void io_ensure_malloced( Buffer *io, size_t bytes )    {    if( UNLIKELY(!io->malloced) )    {    /* convert to malloced buffer from a shared one. */    if( !io_unstash_malloc(io) )    {    unsigned char *old = io->buffer; -  io->buffer = xalloc( io->len + bytes + 100 ); +  +  bytes += io->len; +  +  if (bytes < io->len || bytes + 100 < bytes) +  Pike_error(msg_out_of_mem_2, bytes + 100); +  +  bytes += 100; +  +  io->buffer = xalloc( bytes );    io->malloced = 1; -  io->allocated = io->len + bytes + 100; +  io->allocated = bytes;    io->num_malloc++;    memcpy( io->buffer, old, io->len );    io_unlink_external_storage(io);    }    }    }       static unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force )    ATTRIBUTE((noclone,noinline));    static unsigned char *io_add_space_do_something( Buffer *io, size_t bytes, int force )
pike.git/src/modules/_Stdio/buffer.cmod:284:    if( UNLIKELY(io->len + bytes > io->allocated) )    {    size_t new_len;    void *new_ptr;      #if SIZEOF_CHARP == 8    new_len = round_up64(io->len+bytes);   #else    new_len = round_up32(io->len+bytes);   #endif -  if( !new_len ) -  Pike_error(msg_out_of_mem_2, io->len+bytes); +  if (!new_len) new_len = io->len + bytes;       new_ptr = xrealloc( io->buffer, new_len );    if( !new_ptr )    Pike_error(msg_out_of_mem_2, new_len );    io->buffer = new_ptr;    io->num_malloc++;    io->allocated = new_len;    }    return io->buffer+io->len;    }