[pango/pango2-windows: 17/19] test-common.c: Avoid overwriting elements of arrays
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2-windows: 17/19] test-common.c: Avoid overwriting elements of arrays
- Date: Sun, 19 Jun 2022 02:49:09 +0000 (UTC)
commit b51df9b75d57d1c07c58d3e55b77201c7fe400f9
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Fri Jun 17 11:36:19 2022 +0800
test-common.c: Avoid overwriting elements of arrays
We are gathering up the files in $(G_TEST_SRCDIR)/fonts using a const
char* to collect and append the *.synthetic and *.generic filenames into
g_ptr_array's, where subsequent appends may overwrite what is already in
the repsective arrays, since we are appending items using the same
pointer addresses.
Avoid this by using unique pointer addresses using g_strdup() to add the
filenames in the respective arrays, and freeing them when we run through
the arrays, after adding them into their respective families or faces.
This will fix a number of tests on Windows, at least on Visual Studio.
tests/test-common.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/tests/test-common.c b/tests/test-common.c
index 031de0e3..09bc9385 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -419,10 +419,10 @@ install_fonts (void)
PangoFontMap *map;
GDir *dir;
GError *error = NULL;
- const char *name;
GPtrArray *generic;
GPtrArray *synthetic;
char *path = NULL;
+ char *name_i = NULL;
map = pango_font_map_new ();
@@ -438,7 +438,7 @@ install_fonts (void)
while (TRUE)
{
- name = g_dir_read_name (dir);
+ const char *name = g_dir_read_name (dir);
if (name == NULL)
break;
@@ -446,9 +446,9 @@ install_fonts (void)
g_str_has_suffix (name, ".otf"))
add_file (map, path, name);
else if (g_str_has_suffix (name, ".generic"))
- g_ptr_array_add (generic, (gpointer) name);
+ g_ptr_array_add (generic, g_strdup (name));
else if (g_str_has_suffix (name, ".synthetic"))
- g_ptr_array_add (synthetic, (gpointer) name);
+ g_ptr_array_add (synthetic, g_strdup (name));
}
/* Add generics and synthetics in a second path,
@@ -456,15 +456,17 @@ install_fonts (void)
*/
for (int i = 0; i < generic->len; i++)
{
- name = g_ptr_array_index (generic, i);
- add_generic_family (map, path, name);
+ name_i = g_ptr_array_index (generic, i);
+ add_generic_family (map, path, name_i);
+ g_free (name_i);
}
g_ptr_array_free (generic, TRUE);
for (int i = 0; i < synthetic->len; i++)
{
- name = g_ptr_array_index (synthetic, i);
- add_synthetic_faces (map, path, name);
+ name_i = g_ptr_array_index (synthetic, i);
+ add_synthetic_faces (map, path, name_i);
+ g_free (name_i);
}
g_ptr_array_free (synthetic, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]