xbps_binpkg_{arch,pkgver}: return a buffer of matched string instead.

... otherwise will pass an invalid pointer to free(3) later on.
This commit is contained in:
Juan RP 2014-11-19 11:56:16 +01:00
parent 428a747fad
commit eb90fcc50c

View File

@ -107,7 +107,7 @@ char *
xbps_binpkg_pkgver(const char *pkg)
{
const char *fname;
char *p, *p1;
char *p, *p1, *res;
unsigned int len;
/* skip path if found, only interested in filename */
@ -131,14 +131,17 @@ xbps_binpkg_pkgver(const char *pkg)
free(p);
return NULL;
}
return p;
res = strdup(p);
assert(res);
free(p);
return res;
}
char *
xbps_binpkg_arch(const char *pkg)
{
const char *fname;
char *p;
char *p, *p1, *res;
unsigned int len;
/* skip path if found, only interested in filename */
@ -153,8 +156,11 @@ xbps_binpkg_arch(const char *pkg)
assert(p);
(void)memcpy(p, fname, len);
p[len] = '\0';
return strrchr(p, '.') + 1;
p1 = strrchr(p, '.') + 1;
assert(p1);
res = strdup(p1);
free(p);
return res;
}
const char *