Branch: Tag:

2017-05-18

2017-05-18 09:26:22 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Stdio.Buffer: Fixed multiple issues with read_le_int().

The threshold for using io_read_number() instead of io_read_bignum()
was off by one (on the safe side).

Fixes broken use of mpz_import() in io_read_bignum().

Fixed typo in documentation.

628:    if( UNLIKELY(io_read_byte_uc(io)) )    Pike_error("Integer (%dbit) overflow.\n", SIZEOF_INT_TYPE*8);    +  /* NB: endian == 0 for little endian, +  * 1 for big endian. +  */    if( endian )    res = io_read_number_uc( io, len );    else
647:    if( !io_avail(io,len) ) return NULL;    o = fast_clone_object(bignum_program);    i = (void*)o->storage; -  mpz_import( i, len, 1, endian, 0, 0, io_read_pointer(io) ); +  /* NB: endian == -1 for little endian, +  * 0 for native, +  * 1 for big endian. +  */ +  mpz_import( i, len, endian, 1, endian, 0, io_read_pointer(io) );    io_consume(io,len);    return o;    }
2445:       Pike_sp--;    -  if( len < SIZEOF_INT_TYPE-1 ) /* will for sure fit. */ +  if( len < SIZEOF_INT_TYPE ) /* will for sure fit. */    {    push_int( io_read_number( io, len, 1 ) );    return;
2460:    push_int(-1);    }    -  /*! @decl int read_int( int n ) +  /*! @decl int read_le_int( int n )    *!    *! Read a big endian byte order unsigned number of size n*8 bits,    *! then return it.
2478:       Pike_sp--;    -  if( len < SIZEOF_INT_TYPE-1 ) /* will for sure fit. */ +  if( len < SIZEOF_INT_TYPE ) /* will for sure fit. */    {    push_int( io_read_number( io, len, 0 ) );    return;    }    -  if( (o = io_read_bignum(io, len, 0)) ) +  if( (o = io_read_bignum(io, len, -1)) )    {    push_object(o);    reduce_stack_top_bignum();