Branch: Tag:

2017-07-30

2017-07-30 09:46:59 by Arne Goedeke <el@laramies.com>

Stdio.Buffer: fix unread()

The documentation promises that unread() will always succeed until new
data is added to the buffer. This contract was broken when the new
growth strategy was added by commit 2c4241823. That commit added a
possible trim to every read operation, which would try to shrink the
buffer and make a future unread() fail.

Also, the max_waste check contained a typo, which made it always
succeed.

This issue does not affect rewind keys.

129:    PMOD_EXPORT void io_trim( Buffer *io )    ATTRIBUTE((noinline));    +  static void io_trim_waste( Buffer *io ) +  { +  if( UNLIKELY(io->allocated > (io_len(io) * (1.0+io->max_waste))) ) +  io_trim(io); +  } +     static int io_is_whitespace( Buffer *io, size_t pos )    {    if( pos > io_len( io ) )
2247:    Buffer *io = THIS;    io->max_waste = howmuch;    io_add_space( io, 0, 1 ); -  io_consume( io, 0 ); +  io_trim_waste( io );    }       /*! @decl void trim()