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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:1086:    *! If there is not enough data available return 0.    *!    *! Note that pike string can not be longer than 0x7fffffff bytes (~2Gb).    */    PIKEFUN string(0..255) read_hstring( int bytes )    {    LONGEST len;    struct pike_string *s;       len = io_read_number( THIS, bytes ); +  +  if (len < 0) { +  /* io_avail() in io_read_number() failed. */ +  push_int(0); +  return; +  } +  +  /* NB: We assume that io_avail() in io_read_string() doesn't throw. */    s = io_read_string( THIS, len ); -  if( s ) +  +  if( s ) {    push_string(s); -  else +  } else { +  io_rewind( THIS, bytes );    push_int(0);    } -  +  }       /*! @decl IOBuffer read_hbuffer( int n )    *! @decl IOBuffer read_hbuffer( int n, bool copy )    *!    *! Same as @[read_hstring], but returns the result as an IOBuffer.    *!    *! No data is copied unless @[copy] is specified and true, the new    *! buffer points into the old one.    *!    *! @note
pike.git/src/modules/_Stdio/buffer.cmod:1114:    *!    *! Usually this is OK, since it often represents something that    *! should be parsed before the next whatever is extracted from    *! the buffer, but do take care.    *!    *! If you need to unlink the new buffer after it has been    *! created, call @[trim] in it.    */    PIKEFUN IOBuffer read_hbuffer( int bytes, int|void copy )    { -  LONGEST len = io_read_number( THIS, bytes ); +  LONGEST len;    int do_copy = 0;    struct object *o; -  +     if( copy ) do_copy = copy->u.integer;    pop_n_elems(args);    -  if( (o = io_read_buffer( THIS, len, do_copy )) ) +  if (!io_avail( THIS, bytes )) { +  push_int(0); +  return; +  } +  +  len = io_read_number( THIS, bytes ); +  +  /* NB: We assume that io_avail() in io_read_buffer() doesn't throw. */ +  o = io_read_buffer( THIS, len, do_copy ); +  +  if( o ) {    push_object(o); -  else +  } else { +  io_rewind( THIS, bytes );    push_int(0);    } -  +  }       /*! @decl IOBuffer read_buffer( int n )    *! @decl IOBuffer read_buffer( int n, bool copy )    *!    *! Same as @[read], but returns the result as an IOBuffer.    *!    *! No data is copied unless @[copy] is specified and true, the new buffer    *! points into the old one.    *!    *! @note