mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-12 07:26:15 +01:00
g_output_stream_write: Allow NULL buffer if count is 0
We currently fail a buffer != NULL assertion if buffer is NULL and count is 0. Allow this case without critical assertions. Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3402
This commit is contained in:
parent
e2a36f8b05
commit
d64336e1a9
@ -216,7 +216,7 @@ g_output_stream_write (GOutputStream *stream,
|
|||||||
gssize res;
|
gssize res;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), -1);
|
g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), -1);
|
||||||
g_return_val_if_fail (buffer != NULL, 0);
|
g_return_val_if_fail (buffer != NULL || count == 0, 0);
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -307,6 +307,7 @@ test_write_null (void)
|
|||||||
{
|
{
|
||||||
GOutputStream *mo;
|
GOutputStream *mo;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
gssize bytes_written;
|
||||||
|
|
||||||
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2471");
|
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2471");
|
||||||
|
|
||||||
@ -316,6 +317,10 @@ test_write_null (void)
|
|||||||
|
|
||||||
g_assert_cmpint (0, ==, g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)));
|
g_assert_cmpint (0, ==, g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (mo)));
|
||||||
|
|
||||||
|
bytes_written = g_output_stream_write (mo, NULL, 0, NULL, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert_cmpint (0, ==, bytes_written);
|
||||||
|
|
||||||
g_output_stream_close (mo, NULL, &error);
|
g_output_stream_close (mo, NULL, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_object_unref (mo);
|
g_object_unref (mo);
|
||||||
|
Loading…
Reference in New Issue
Block a user