whereis: avoid printing uninitialized string

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

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2014-07-13 18:13:38 +01:00
parent 7370501f60
commit 46ed183613
1 changed files with 1 additions and 2 deletions

View File

@ -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';