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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:196:    io->buffer = xalloc( io->len + bytes + 100 );    io->malloced = 1;    io->allocated = io->len + bytes + 100;    io->num_malloc++;    memcpy( io->buffer, old, io->len );    io_unlink_external_storage(io);    }    }    }    -  static unsigned char *io_add_space_do_something( IOBuffer *io, int bytes, int force ) +  static unsigned char *io_add_space_do_something( IOBuffer *io, size_t bytes, int force )    ATTRIBUTE((noclone,noinline)); -  static unsigned char *io_add_space_do_something( IOBuffer *io, int bytes, int force ) +  static unsigned char *io_add_space_do_something( IOBuffer *io, size_t bytes, int force )    { -  +  if( bytes && io->len+bytes < io->len ) +  Pike_error("Too large buffer, can not have more than %lu bytes", +  (size_t)-1); +  +     io_ensure_unlocked(io);    io_ensure_malloced(io, bytes);       /*    * It is actually not certain that checking this is a good idea.    *    * The reason being that if the current buffer size is very small    * (io_len(io)) and the bytes added is large and there is an    * offset, it makes sense to move now when we do not have to copy    * as much.
pike.git/src/modules/_Stdio/buffer.cmod:262:    new_len = ((new_len+32)*2)-32;    while( new_len < io->len + bytes );       io->buffer = xrealloc( io->buffer, new_len );    io->num_malloc++;    io->allocated = new_len;    }    return io->buffer+io->len;    }    -  static unsigned char *io_add_space( IOBuffer *io, int bytes, int force ) +  static unsigned char *io_add_space( IOBuffer *io, size_t bytes, int force )    {    if( io->len == io->offset )    io->offset = io->len = 0; -  if( !force && io->malloced && !io->locked && io->len+bytes < io->allocated ) +  if( !force && io->malloced && !io->locked && io->len+bytes < io->allocated && +  (!bytes || io->len+bytes > io->len))    return io->buffer+io->len;    return io_add_space_do_something( io, bytes, force );    }       /*! @decl protected bool range_error( int howmuch )    *!    *! This function is called when an attempt is made to read out of bounds.    *!    *! The default implementation simply returns @expr{0@} (zero).    *!
pike.git/src/modules/_Stdio/buffer.cmod:333:    }    else    push_text("Illegal arguments\n");       ref_push_object( io->this );    push_object(clone_object(io->error_mode, 2));    f_throw(1);    }    }    -  static struct pike_string *io_read_string( IOBuffer *io, size_t len ) +  static struct pike_string *io_read_string( IOBuffer *io, ssize_t len )    ATTRIBUTE((noclone,noinline));    static size_t io_rewind( IOBuffer *io, INT_TYPE n );       static void io_do_rewind_on_error( struct rewind_to *e )    {    e->io->locked_move--;    e->io->offset = e->rewind_to;    free( e );    }   
pike.git/src/modules/_Stdio/buffer.cmod:498:       if( (total/(size_t)each) < (size_t)len )    {    if( io_range_error( io, len+io->len-io->offset ) )    return io_avail_mul(io,len,each);    return 0;    }    return 1;    }    -  static void io_append( IOBuffer *io, const void *p, int bytes ) +  static void io_append( IOBuffer *io, const void *p, size_t bytes )    {    memcpy( io_add_space( io, bytes, 0 ), p, bytes );    io->len += bytes;    io_trigger_output( io );    }       static size_t io_read( IOBuffer *io, void *to, size_t len )    {    if( !io_avail(io,len))    return 0;    memcpy( to, io_read_pointer(io), len );    io_consume( io, len );    return len;    }    -  static struct pike_string *io_read_string( IOBuffer *io, size_t len ) +  static struct pike_string *io_read_string( IOBuffer *io, ssize_t len )    {    struct pike_string *s;       if( len > 0x7fffffff )    Pike_error("This region is too large to convert to a string.\n");    -  +  if( len < 0 ) +  return make_shared_binary_string(NULL,0); +     if( !io_avail(io,len))    return NULL;       s = begin_shared_string( len );    io_read( io, s->str, len );    return end_shared_string(s);    }       static struct object *io_read_buffer( IOBuffer *io, size_t len, int do_copy )    {
pike.git/src/modules/_Stdio/buffer.cmod:1066:       /*! @decl IOBuffer add_hstring( string(0..255) data, int size_size )    *! @decl IOBuffer add_hstring( Stdio.IOBuffer data, int size_size )    *! @decl IOBuffer add_hstring( System.Memory data, int size_size )    *! @decl IOBuffer add_hstring( String.Buffer data, int size_size )    *! @decl IOBuffer add_hstring( array data, int size_size )    *!    *! Adds length of data followed by @[data] to the buffer.    *!    *! This is identical to -  *! @code{sprintf("%"+size_size+"H",(string)Stdio.IObuffer(data))@} but +  *! @tt{sprintf("%"+size_size+"H",(string)Stdio.IObuffer(data))@} but    *! significantly faster.    *!    *! @[size_size] is the number of bytes used to represent the length of the data.    *! It must be less than Int.NATIVE_MAX.    *!    *! The supported @[data] argument types are    *!    *! @mixed    *! @type string(0..255)    *! An eight bit string.
pike.git/src/modules/_Stdio/buffer.cmod:1850:    *! @returns    *! If the buffer contains less than @[len] bytes    *! of data, the entire buffer contents are returned.    *! Otherwise the first @[len] bytes are returned.    *!    *! @seealso    *! @[read()]    */    PIKEFUN string(0..255) try_read( int bytes )    { +  IOBuffer *this = THIS;    struct pike_string *s;    Pike_sp--; -  if (bytes > io_len(THIS)) -  bytes = io_len(THIS); -  push_string( io_read_string(THIS, bytes )); +  /* Hm. signed/unsigned comparisons abound. */ +  if( bytes > 0 && bytes > io_len(this) ) +  bytes = io_len(this); +  push_string( io_read_string(this, bytes ) );    }       /*! @decl int(8bit) read_int8()    */    PIKEFUN int(8bit) read_int8( )    {    IOBuffer *io = THIS;    if( LIKELY(io_avail( io, 1 )) )    push_int( io_read_byte_uc(io) );    else