[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: appstream-glib: FTBFS on hurd-i396 (for review)



On Wed, 2014-10-22 at 10:29 +0200, Pino Toscano wrote:
> On 2014-10-22 10:21, Svante Signell wrote:
> > On Wed, 2014-10-22 at 01:21 +0200, Samuel Thibault wrote:
> >> Svante Signell, le Tue 21 Oct 2014 12:34:22 +0200, a écrit :

> > +       free (tmp);
> > +       return ret;
> >  }
> 
> glib has g_strdup_printf, so just make use of it instead of doing
> custom malloc code; 

Updated patch attached. For the first part of the patch, I don't find
using g_strdup_printf() is an advantage over g_malloc(), since later on
g_realloc() is needed.

> also, use g_free instead of free.

This was a typo, see the rest of the patch.


Index: appstream-glib-0.3.0/client/as-util.c
===================================================================
--- appstream-glib-0.3.0.orig/client/as-util.c
+++ appstream-glib-0.3.0/client/as-util.c
@@ -767,9 +767,9 @@ static gboolean
 as_util_install_icons (const gchar *filename, const gchar *origin, GError **error)
 {
 	const gchar *destdir;
-	const gchar *tmp;
+	const gchar *tmp, *pathname;
 	gboolean ret = TRUE;
-	gchar buf[PATH_MAX];
+	gchar *buf = NULL;
 	gsize len;
 	int r;
 	struct archive *arch = NULL;
@@ -817,27 +817,34 @@ as_util_install_icons (const gchar *file
 		}
 
 		/* no output file */
-		if (archive_entry_pathname (entry) == NULL)
+		pathname = archive_entry_pathname (entry);
+		if (pathname == NULL)
 			continue;
 
 		/* update output path */
-		g_snprintf (buf, PATH_MAX, "%s/%s",
-			    dir, archive_entry_pathname (entry));
+		len = strlen (dir) + 1 + strlen (pathname) + 1;
+		buf = g_malloc(len);
+		g_snprintf (buf, len, "%s/%s", dir, pathname);
 		archive_entry_update_pathname_utf8 (entry, buf);
 
 		/* update hardlinks */
 		tmp = archive_entry_hardlink (entry);
 		if (tmp != NULL) {
-			g_snprintf (buf, PATH_MAX, "%s/%s", dir, tmp);
+			len = strlen (dir) + 1 + strlen (tmp) + 1;
+			buf = g_realloc (buf, len);
+			g_snprintf (buf, len, "%s/%s", dir, tmp);
 			archive_entry_update_hardlink_utf8 (entry, buf);
 		}
 
 		/* update symlinks */
 		tmp = archive_entry_symlink (entry);
 		if (tmp != NULL) {
-			g_snprintf (buf, PATH_MAX, "%s/%s", dir, tmp);
+			len = strlen (dir) + 1 + strlen (tmp) + 1;
+			buf = g_realloc (buf, len);
+			g_snprintf (buf, len, "%s/%s", dir, tmp);
 			archive_entry_update_symlink_utf8 (entry, buf);
 		}
+		g_free (buf);
 
 		r = archive_read_extract (arch, entry, 0);
 		if (r != ARCHIVE_OK) {
Index: appstream-glib-0.3.0/libappstream-builder/asb-utils.c
===================================================================
--- appstream-glib-0.3.0.orig/libappstream-builder/asb-utils.c
+++ appstream-glib-0.3.0/libappstream-builder/asb-utils.c
@@ -184,7 +184,8 @@ asb_utils_explode_file (struct archive_e
 			GPtrArray *glob)
 {
 	const gchar *tmp;
-	gchar buf[PATH_MAX];
+	gsize len;
+	gchar *buf = NULL;
 	_cleanup_free_ gchar *path = NULL;
 
 	/* no output file */
@@ -206,22 +207,29 @@ asb_utils_explode_file (struct archive_e
 	}
 
 	/* update output path */
-	g_snprintf (buf, PATH_MAX, "%s/%s", dir, tmp);
+	len = strlen (dir) + 1 + strlen(tmp) + 1;
+	buf = g_malloc (len);
+	g_snprintf (buf, len, "%s/%s", dir, tmp);
 	archive_entry_update_pathname_utf8 (entry, buf);
 
 	/* update hardlinks */
 	tmp = archive_entry_hardlink (entry);
 	if (tmp != NULL) {
-		g_snprintf (buf, PATH_MAX, "%s/%s", dir, tmp);
+		len = strlen (dir) + 1 + strlen(tmp) + 1;
+		buf = g_realloc (buf, len);
+		g_snprintf (buf, len, "%s/%s", dir, tmp);
 		archive_entry_update_hardlink_utf8 (entry, buf);
 	}
 
 	/* update symlinks */
 	tmp = archive_entry_symlink (entry);
 	if (tmp != NULL) {
-		g_snprintf (buf, PATH_MAX, "%s/%s", dir, tmp);
+		len = strlen (dir) + 1 + strlen(tmp) + 1;
+		buf = g_realloc (buf, len);
+		g_snprintf (buf, len, "%s/%s", dir, tmp);
 		archive_entry_update_symlink_utf8 (entry, buf);
 	}
+	free (buf);
 	return TRUE;
 }
 
Index: appstream-glib-0.3.0/libappstream-builder/plugins/asb-plugin-gstreamer.c
===================================================================
--- appstream-glib-0.3.0.orig/libappstream-builder/plugins/asb-plugin-gstreamer.c
+++ appstream-glib-0.3.0/libappstream-builder/plugins/asb-plugin-gstreamer.c
@@ -111,9 +111,10 @@ static const AsbGstreamerDescData data[]
 static gboolean
 asb_utils_is_file_in_tmpdir (const gchar *tmpdir, const gchar *filename)
 {
-	gchar tmp[PATH_MAX];
-	g_snprintf (tmp, PATH_MAX, "%s/%s", tmpdir, filename);
-	return g_file_test (tmp, G_FILE_TEST_EXISTS);
+	char *tmp = g_strdup_printf ("%s/%s", tmpdir, filename);
+	gboolean ret = g_file_test (tmp, G_FILE_TEST_EXISTS);
+	g_free (tmp);
+	return ret;
 }
 
 /**

Reply to: