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 <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall 2024-10-15 11:49:33 +01:00
parent e3e936f7ba
commit 50ccb04c71
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -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 },
};