break;
case G_SEEK_END:
- absolute = priv->len + offset;
+ /* For resizable streams, we consider the end to be the data
+ * length. For fixed-sized streams, we consider the end to be the
+ * size of the buffer.
+ */
+ if (priv->realloc_fn)
+ absolute = priv->valid_len + offset;
+ else
+ absolute = priv->len + offset;
break;
default:
return FALSE;
}
- if (absolute > priv->len)
+ /* Can't seek past the end of a fixed-size stream.
+ *
+ * Note: seeking to the non-existent byte at the end of a fixed-sized
+ * stream is valid (eg: a 1-byte fixed sized stream can have position
+ * 0 or 1). Therefore '>' is what we want.
+ * */
+ if (priv->realloc_fn == NULL && absolute > priv->len)
{
g_set_error_literal (error,
G_IO_ERROR,
GError *error;
const gchar buffer[] = "abcdefghijklmnopqrstuvwxyz";
- base = g_memory_output_stream_new (g_malloc0 (20), 20, g_realloc, g_free);
+ base = g_memory_output_stream_new (g_malloc0 (20), 20, NULL, g_free);
out = g_buffered_output_stream_new (base);
g_assert_cmpint (g_buffered_output_stream_get_buffer_size (G_BUFFERED_OUTPUT_STREAM (out)), ==, 4096);
gboolean ret;
const gchar buffer[] = "abcdefghijklmnopqrstuvwxyz";
- base = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (g_malloc0 (30), 30, g_realloc, g_free));
+ base = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (g_malloc0 (30), 30, NULL, g_free));
out = g_buffered_output_stream_new_sized (G_OUTPUT_STREAM (base), 8);
seekable = G_SEEKABLE (out);
error = NULL;
GOutputStream *mo;
GError *error;
- mo = g_memory_output_stream_new (g_new (gchar, 100), 100, g_realloc, g_free);
+ mo = g_memory_output_stream_new (g_new (gchar, 100), 100, NULL, g_free);
g_assert (G_IS_SEEKABLE (mo));
g_assert (g_seekable_can_seek (G_SEEKABLE (mo)));