xbps-query: fixed some issues found by pancake and valgrind.
This commit is contained in:
parent
298072ced3
commit
924ef35a07
@ -57,8 +57,8 @@ list_pkgs_in_dict(struct xbps_handle *xhp,
|
||||
{
|
||||
struct list_pkgver_cb *lpc = arg;
|
||||
const char *pkgver, *short_desc, *arch;
|
||||
char *tmp = NULL, *out = NULL;
|
||||
size_t i, len = 0;
|
||||
char tmp[255], *out = NULL;
|
||||
size_t i, len = 0, maxcols;
|
||||
bool chkarch;
|
||||
|
||||
(void)xhp;
|
||||
@ -73,25 +73,22 @@ list_pkgs_in_dict(struct xbps_handle *xhp,
|
||||
if (!pkgver && !short_desc)
|
||||
return EINVAL;
|
||||
|
||||
tmp = calloc(1, lpc->pkgver_len + 1);
|
||||
assert(tmp);
|
||||
memcpy(tmp, pkgver, lpc->pkgver_len);
|
||||
for (i = strlen(tmp); i < lpc->pkgver_len; i++)
|
||||
strncpy(tmp, pkgver, sizeof(tmp));
|
||||
for (i = strlen(pkgver); i < lpc->pkgver_len; i++)
|
||||
tmp[i] = ' ';
|
||||
|
||||
tmp[i] = '\0';
|
||||
len = strlen(tmp) + strlen(short_desc) + 1;
|
||||
if (len > lpc->maxcols) {
|
||||
maxcols = lpc->maxcols - 4;
|
||||
len = strlen(tmp) + strlen(short_desc);
|
||||
if (len > maxcols) {
|
||||
out = malloc(lpc->maxcols);
|
||||
assert(out);
|
||||
snprintf(out, lpc->maxcols-2, "%s %s", tmp, short_desc);
|
||||
strncat(out, "...", lpc->maxcols);
|
||||
printf("%s\n", out);
|
||||
snprintf(out, maxcols, "%s %s", tmp, short_desc);
|
||||
printf("%s...\n", out);
|
||||
free(out);
|
||||
} else {
|
||||
printf("%s %s\n", tmp, short_desc);
|
||||
}
|
||||
free(tmp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,12 +87,14 @@ repo_search_pkgs_cb(struct xbps_rindex *rpi, void *arg, bool *done)
|
||||
prop_dictionary_keysym_t ksym;
|
||||
struct repo_search_data *rsd = arg;
|
||||
const char *pkgver, *pkgname, *desc, *inststr;
|
||||
char *tmp = NULL, *out = NULL;
|
||||
size_t i, j, len;
|
||||
char tmp[255], *out = NULL;
|
||||
size_t i, j, len, maxcols;
|
||||
int x;
|
||||
|
||||
(void)done;
|
||||
|
||||
maxcols = rsd->maxcols - 4; /* - "...\n" */
|
||||
|
||||
allkeys = prop_dictionary_all_keys(rpi->repod);
|
||||
for (i = 0; i < prop_array_count(allkeys); i++) {
|
||||
ksym = prop_array_get(allkeys, i);
|
||||
@ -108,9 +110,7 @@ repo_search_pkgs_cb(struct xbps_rindex *rpi, void *arg, bool *done)
|
||||
(strcasecmp(pkgname, rsd->patterns[x]) == 0) ||
|
||||
(strcasestr(pkgver, rsd->patterns[x])) ||
|
||||
(strcasestr(desc, rsd->patterns[x]))) {
|
||||
tmp = calloc(1, rsd->pkgver_len + 1);
|
||||
assert(tmp);
|
||||
memcpy(tmp, pkgver, rsd->pkgver_len);
|
||||
strncpy(tmp, pkgver, sizeof(tmp));
|
||||
for (j = strlen(tmp); j < rsd->pkgver_len; j++)
|
||||
tmp[j] = ' ';
|
||||
|
||||
@ -121,21 +121,18 @@ repo_search_pkgs_cb(struct xbps_rindex *rpi, void *arg, bool *done)
|
||||
inststr = "[-]";
|
||||
|
||||
len = strlen(inststr) + strlen(tmp) +
|
||||
strlen(desc) + 1;
|
||||
if (len > rsd->maxcols) {
|
||||
out = malloc(rsd->maxcols+1);
|
||||
strlen(desc);
|
||||
if (len > maxcols) {
|
||||
out = malloc(maxcols);
|
||||
assert(out);
|
||||
snprintf(out, rsd->maxcols-3, "%s %s %s",
|
||||
snprintf(out, maxcols, "%s %s %s",
|
||||
inststr, tmp, desc);
|
||||
strncat(out, "...", rsd->maxcols);
|
||||
out[rsd->maxcols+1] = '\0';
|
||||
printf("%s\n", out);
|
||||
printf("%s...\n", out);
|
||||
free(out);
|
||||
} else {
|
||||
printf("%s %s %s\n", inststr,
|
||||
tmp, desc);
|
||||
}
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
|
||||
prop_array_get_cstring_nocopy(reqby, i, &pkgdep);
|
||||
printf("%s\n", pkgdep);
|
||||
}
|
||||
prop_object_release(reqby);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -105,13 +105,15 @@ print_value_obj(const char *keyname, prop_object_t obj,
|
||||
} else {
|
||||
FILE *f;
|
||||
char buf[BUFSIZ-1];
|
||||
void *data;
|
||||
|
||||
f = fmemopen(prop_data_data(obj),
|
||||
prop_data_size(obj), "r");
|
||||
data = prop_data_data(obj);
|
||||
f = fmemopen(data, prop_data_size(obj), "r");
|
||||
assert(f);
|
||||
while (fgets(buf, BUFSIZ-1, f))
|
||||
printf("%s", buf);
|
||||
fclose(f);
|
||||
free(data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -284,6 +286,7 @@ int
|
||||
repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
int rv;
|
||||
|
||||
pkgd = xbps_rpool_get_pkg_plist(xhp, pkg, "./files.plist");
|
||||
if (pkgd == NULL) {
|
||||
@ -294,5 +297,8 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
|
||||
}
|
||||
}
|
||||
|
||||
return show_pkg_files(pkgd);
|
||||
rv = show_pkg_files(pkgd);
|
||||
prop_object_release(pkgd);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user