[PATCH 11/14] whereis: avoid printing uninitialized string

Sami Kerola
2014-07-13T20:25:35Z

The patbuf[] needs to be filled before print out.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/whereis.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index ba83b15..5339aba 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -408,13 +408,12 @@ static void lookup(const char *pattern, struct wh_dirlist *ls, int want)
int count = 0;
char *wait = NULL, *p;

- DBG(printf("lookup dirs for '%s' (%s)", patbuf, pattern));
-
/* canonicalize pattern -- remove path suffix etc. */
p = strrchr(pattern, '/');
p = p ? p + 1 : (char *) pattern;
strncpy(patbuf, p, PATH_MAX);
patbuf[PATH_MAX - 1] = '\0';
+ DBG(printf("lookup dirs for '%s' (%s)", patbuf, pattern));
p = strrchr(patbuf, '.');
if (p)
*p = '\0';
--
2.0.1