From 50ccb04c71c95966a40849b21be98b587ef60248 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 15 Oct 2024 11:49:33 +0100 Subject: [PATCH] tests: Fix 1-byte overread in data-input-stream tests Commit 760a6f647 rearranged how the lengths are calculated for the test data and added `escape_data_string()` so they could be printed safely. Unfortunately there was a miscount in the length of the first test vector in `test_read_upto()`: there are 31 bytes in the string literal, plus one nul terminator which is added by the compiler. The quoted string length was 32 bytes. This should be fine (explicitly including the nul delimiter), but then `escape_data_string()` adds another byte to the length because it assumes the nul delimiter has *not* been included in the count. Changing the string length from 32 to 31 breaks the tests, as the final component of the data is then the wrong length, so add an additional explicit nul byte to the string literal so that it matches the length. Signed-off-by: Philip Withnall --- gio/tests/data-input-stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/tests/data-input-stream.c b/gio/tests/data-input-stream.c index 11c997bce..163231e1c 100644 --- a/gio/tests/data-input-stream.c +++ b/gio/tests/data-input-stream.c @@ -314,7 +314,7 @@ test_read_upto (void) const char *data_sep; size_t data_sep_len; } vectors[] = { - { 10, " part1 # part2 $ part3 \0 part4 ", 32, 7, "#$\0^", 4 }, + { 10, " part1 # part2 $ part3 \0 part4 \0", 32, 7, "#$\0^", 4 }, { 20, "{\"key\": \"value\"}\0", 17, 16, "\0", 1 }, };