From 30437b47c81590bf8b9efffd19f9a42e6112b9cb Mon Sep 17 00:00:00 2001 From: Daniel Macks Date: Wed, 12 Nov 2014 07:47:57 -0800 Subject: [PATCH] Use same token for malloc as for string construction The goal is for pkgname to hold the name without the trailing ".pc" extension (according to the meaning of EXT_LEN as used in the ends_in_dotpc() function). But the malloc is hardcoded as 2. If the extension were to be changed, the number of characters being strncpy'ed would not match the size of the target buffer. Instead, the malloc should use the EXT_LEN token (adjusted for the trailing \0). Freedesktop #80378 (https://bugs.freedesktop.org/show_bug.cgi?id=80378) --- pkg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg.c b/pkg.c index 2d13a52..825c38a 100644 --- a/pkg.c +++ b/pkg.c @@ -178,7 +178,7 @@ scan_dir (char *dirname) if (ends_in_dotpc (dent->d_name)) { - char *pkgname = g_malloc (len - 2); + char *pkgname = g_malloc (len - EXT_LEN + 1); debug_spew ("File '%s' appears to be a .pc file\n", dent->d_name);