GNOME Bugzilla – Bug 720080
Truncating a GMemoryOutputStream to a larger size causes get_data_size() to be incorrect
Last modified: 2013-12-15 23:51:23 UTC
As per the bug description. This came up when working on bug 720062.
Created attachment 263775 [details] [review] gio: Update GMemoryOutputStream length after truncate For GMemoryOutputStream, update valid_len when truncating so that g_memory_output_stream_get_data_size () returns the correct result.
Review of attachment 263775 [details] [review]: ::: gio/tests/memory-output-stream.c @@ +55,3 @@ + g_seekable_truncate (G_SEEKABLE (mo), 8192, NULL, &error); + g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)), ==, 8192); + Do we guarantee that the extra data reads as zeros ? If yes, would be good to test that too.
See bug 684842 about recent activity here. Particularly, be careful about the fixed-sized case. It looks like array_resize() will error out in that case anyway, so I think this is probably fine. As for reading extra zero bytes in the non-fixed-sized case, I think that would indeed be consistent with the view of a seekable non-fixed-size output stream behaving similarly to a file. Probably worth putting under a test.
Attachment 263775 [details] pushed as 3b9ad6e - gio: Update GMemoryOutputStream length after truncate