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:
parent
428a747fad
commit
eb90fcc50c
16
lib/util.c
16
lib/util.c
@ -107,7 +107,7 @@ char *
|
|||||||
xbps_binpkg_pkgver(const char *pkg)
|
xbps_binpkg_pkgver(const char *pkg)
|
||||||
{
|
{
|
||||||
const char *fname;
|
const char *fname;
|
||||||
char *p, *p1;
|
char *p, *p1, *res;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
|
||||||
/* skip path if found, only interested in filename */
|
/* skip path if found, only interested in filename */
|
||||||
@ -131,14 +131,17 @@ xbps_binpkg_pkgver(const char *pkg)
|
|||||||
free(p);
|
free(p);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return p;
|
res = strdup(p);
|
||||||
|
assert(res);
|
||||||
|
free(p);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
xbps_binpkg_arch(const char *pkg)
|
xbps_binpkg_arch(const char *pkg)
|
||||||
{
|
{
|
||||||
const char *fname;
|
const char *fname;
|
||||||
char *p;
|
char *p, *p1, *res;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
|
||||||
/* skip path if found, only interested in filename */
|
/* skip path if found, only interested in filename */
|
||||||
@ -153,8 +156,11 @@ xbps_binpkg_arch(const char *pkg)
|
|||||||
assert(p);
|
assert(p);
|
||||||
(void)memcpy(p, fname, len);
|
(void)memcpy(p, fname, len);
|
||||||
p[len] = '\0';
|
p[len] = '\0';
|
||||||
|
p1 = strrchr(p, '.') + 1;
|
||||||
return strrchr(p, '.') + 1;
|
assert(p1);
|
||||||
|
res = strdup(p1);
|
||||||
|
free(p);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
Loading…
Reference in New Issue
Block a user