1 |
commit: c1a168f95699da8d2ac659cb6ea0c7fb3f4c0df9 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Nov 27 20:02:38 2015 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Nov 27 20:02:38 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c1a168f9 |
7 |
|
8 |
qcache: use xasprintf instead of alloc+snprintf |
9 |
|
10 |
qcache.c | 17 +++++------------ |
11 |
1 file changed, 5 insertions(+), 12 deletions(-) |
12 |
|
13 |
diff --git a/qcache.c b/qcache.c |
14 |
index 5d915bd..9e41c3c 100644 |
15 |
--- a/qcache.c |
16 |
+++ b/qcache.c |
17 |
@@ -537,9 +537,7 @@ int qcache_traverse(void (*func)(qcache_data*)) |
18 |
|
19 |
/* traverse packages */ |
20 |
for (j = 0; j < num_pkg; j++) { |
21 |
- len = sizeof(char) * (strlen(portdir) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(packages[j]->d_name) + 1); |
22 |
- ebuildpath = xzalloc(len); |
23 |
- snprintf(ebuildpath, len, "%s/%s/%s", portdir, categories[i]->d_name, packages[j]->d_name); |
24 |
+ xasprintf(&ebuildpath, "%s/%s/%s", portdir, categories[i]->d_name, packages[j]->d_name); |
25 |
|
26 |
if (-1 == (num_ebuild = scandir(ebuildpath, &ebuilds, qcache_ebuild_select, qcache_vercmp))) { |
27 |
warnp("%s", ebuildpath); |
28 |
@@ -561,10 +559,8 @@ int qcache_traverse(void (*func)(qcache_data*)) |
29 |
|
30 |
/* traverse ebuilds */ |
31 |
for (k = 0; k < num_ebuild; k++) { |
32 |
- len = sizeof(char) * (strlen(catpath) + strlen("/") + strlen(categories[i]->d_name) + strlen("/") + strlen(ebuilds[k]->d_name) + 1); |
33 |
- cachepath = xzalloc(len); |
34 |
- snprintf(cachepath, len, "%s/%s/%s", catpath, categories[i]->d_name, ebuilds[k]->d_name); |
35 |
- cachepath[len-8] = '\0'; /* remove ".ebuild" */ |
36 |
+ len = xasprintf(&cachepath, "%s/%s/%s", catpath, categories[i]->d_name, ebuilds[k]->d_name); |
37 |
+ cachepath[len - 7] = '\0'; /* remove ".ebuild" */ |
38 |
|
39 |
data.category = categories[i]->d_name; |
40 |
data.package = packages[j]->d_name; |
41 |
@@ -886,12 +882,9 @@ _q_static |
42 |
int qcache_init(void) |
43 |
{ |
44 |
char *filename; |
45 |
- unsigned int len; |
46 |
+ int len; |
47 |
|
48 |
- len = sizeof(char) * (strlen(portdir) + strlen("/profiles/arch.list") + 1); |
49 |
- filename = xzalloc(len); |
50 |
- |
51 |
- snprintf(filename, len, "%s/profiles/arch.list", portdir); |
52 |
+ xasprintf(&filename, "%s/profiles/arch.list", portdir); |
53 |
|
54 |
if (NULL == (archlist = qcache_read_lines(filename))) { |
55 |
free(filename); |