diff --git a/gio/gdatainputstream.c b/gio/gdatainputstream.c index ce6175951..ef728f006 100644 --- a/gio/gdatainputstream.c +++ b/gio/gdatainputstream.c @@ -840,7 +840,11 @@ g_data_input_stream_read_line_utf8 (GDataInputStream *stream, g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE, _("Invalid byte sequence in conversion input")); + + if (length != NULL) + *length = 0; g_free (res); + return NULL; } return res; diff --git a/gio/tests/data-input-stream.c b/gio/tests/data-input-stream.c index 8a1e8fb28..11c997bce 100644 --- a/gio/tests/data-input-stream.c +++ b/gio/tests/data-input-stream.c @@ -80,9 +80,9 @@ test_read_lines (GDataStreamNewlineType newline_type) lines[i] = "some_text"; base_stream = g_memory_input_stream_new (); - g_assert (base_stream != NULL); + g_assert_nonnull (base_stream); stream = G_INPUT_STREAM (g_data_input_stream_new (base_stream)); - g_assert(stream != NULL); + g_assert_nonnull (stream); /* Byte order testing */ g_data_input_stream_set_byte_order (G_DATA_INPUT_STREAM (stream), G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN); @@ -174,8 +174,17 @@ test_read_lines_LF_valid_utf8 (void) gsize length = -1; line = g_data_input_stream_read_line_utf8 (G_DATA_INPUT_STREAM (stream), &length, NULL, &error); g_assert_no_error (error); + if (line == NULL) - break; + { + g_assert_cmpuint (length, ==, 0); + break; + } + else + { + g_assert_cmpuint (length, >, 0); + } + n_lines++; g_free (line); } @@ -207,11 +216,16 @@ test_read_lines_LF_invalid_utf8 (void) gsize length = -1; line = g_data_input_stream_read_line_utf8 (G_DATA_INPUT_STREAM (stream), &length, NULL, &error); if (n_lines == 0) - g_assert_no_error (error); + { + /* First line is valid UTF-8 */ + g_assert_no_error (error); + g_assert_cmpuint (length, ==, 3); + } else { - g_assert (error != NULL); + g_assert_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE); g_clear_error (&error); + g_assert_cmpuint (length, ==, 0); g_free (line); break; } @@ -354,7 +368,7 @@ test_read_upto (void) line++; stop_char = g_data_input_stream_read_byte (G_DATA_INPUT_STREAM (stream), NULL, &error); - g_assert (memchr (DATA_SEP, stop_char, DATA_SEP_LEN) != NULL); + g_assert_nonnull (memchr (DATA_SEP, stop_char, DATA_SEP_LEN)); g_assert_no_error (error); } g_free (data);