mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-14 00:06:24 +01:00
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:
parent
6fec7720da
commit
854fd11422
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user