array-test: Don't rely on endianness of multi-byte numbers

The array is an array of bytes in this part of the test, so we need to
append a single byte. Previously we were reusing val (a size_t variable)
from earlier in the test, but because g_array_append_val passes the value
by reference, appending a multi-byte number to an array of bytes will
take the first byte of the number's memory representation, which has the
desired value on little-endian CPUs but is zero on big-endian, leading
to a test failure.

Resolves: https://gitlab.gnome.org/GNOME/glib/-/issues/2918
Bug-Debian: https://bugs.debian.org/1031271
Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2023-02-14 10:34:09 +00:00
parent 6fec7720da
commit 854fd11422

View File

@ -265,8 +265,8 @@ array_new_take_zero_terminated (void)
for (guint8 i = 1; i < array_size; i++)
g_array_append_val (garray, i);
val = G_MAXUINT8 / 2;
g_array_append_val (garray, val);
guint8 byte_val = G_MAXUINT8 / 2;
g_array_append_val (garray, byte_val);
data = g_array_steal (garray, &len);
g_assert_cmpuint (array_size, ==, len);
@ -285,10 +285,10 @@ array_new_take_zero_terminated (void)
g_assert_cmpmem (old_data_copy, array_size * sizeof (guint8),
garray->data, array_size * sizeof (guint8));
val = 55;
g_array_append_val (garray, val);
val = 33;
g_array_prepend_val (garray, val);
byte_val = 55;
g_array_append_val (garray, byte_val);
byte_val = 33;
g_array_prepend_val (garray, byte_val);
g_assert_cmpuint (garray->len, ==, array_size + 2);
g_assert_cmpuint (g_array_index (garray, guint8, 0), ==, 33);