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 :
> 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);
> + gsize len = strlen (tmpdir) + 1 + strlen (filename) + 1;
> + gchar tmp = g_malloc (len);
> + g_snprintf (tmp, len, "%s/%s", tmpdir, filename);
> return g_file_test (tmp, G_FILE_TEST_EXISTS);
> }
This is missing a free.
Is this better?
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);
+ gboolean ret;
+ gsize len = strlen (tmpdir) + 1 + strlen (filename) + 1;
+ gchar *tmp = g_malloc (len);
+ g_snprintf (tmp, len, "%s/%s", tmpdir, filename);
+ ret = g_file_test (tmp, G_FILE_TEST_EXISTS);
+ free (tmp);
+ return ret;
}
glib has g_strdup_printf, so just make use of it instead of doing
custom malloc code; also, use g_free instead of free.
--
Pino Toscano
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]
Archive:
https://lists.debian.org/[email protected]