fix handling of length with strncat

The length arg in the strncat func represents the max number of bytes
that may be appended, but the total length of the buffer.  So we have
to subtract the length of bytes already in there.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
feature/tap-sh
Mike Frysinger 2012-04-29 23:58:52 -04:00 committed by William Pitcock
parent c13acaca47
commit 4e4c1d628a
1 changed files with 4 additions and 2 deletions

6
pkg.c
View File

@ -32,17 +32,19 @@ pkg_get_pkgconfig_path(void)
static bool computed = false;
static char path[PKG_CONFIG_PATH_SZ];
char *env_path;
size_t len;
if (computed)
return path;
strncpy(path, PKG_DEFAULT_PATH, sizeof path);
len = strlen(PKG_DEFAULT_PATH);
env_path = getenv("PKG_CONFIG_PATH");
if (env_path != NULL)
{
strncat(path, ":", sizeof path);
strncat(path, env_path, sizeof path);
strncat(path, ":", sizeof path - len - 1);
strncat(path, env_path, sizeof path - len - 2);
}
return path;