Skip to content

Commit 4fc3610

Browse files
committed
lib: use xbps_error_oom
1 parent 39803ba commit 4fc3610

3 files changed

Lines changed: 19 additions & 34 deletions

File tree

lib/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ xbps_archive_get_file(struct archive *ar, struct archive_entry *entry)
5757

5858
buf = malloc(len + 1);
5959
if (!buf) {
60-
xbps_error_printf("out of memory\n");
60+
xbps_error_oom();
6161
errno = ENOMEM;
6262
return NULL;
6363
}

lib/conf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ vpkg_map_add(xbps_dictionary_t d, const char *pkgname, const char *vpkgver, cons
6161
if (!providers) {
6262
providers = xbps_dictionary_create();
6363
if (!providers)
64-
return -ENOMEM;
64+
return xbps_error_oom();
6565

6666
if (!xbps_dictionary_set(d, pkgname, providers)) {
6767
xbps_object_release(providers);
68-
return -ENOMEM;
68+
return xbps_error_oom();
6969
}
7070
alloc = true;
7171
}
7272

7373
if (!xbps_dictionary_set_cstring(providers, vpkgver, provider)) {
7474
if (alloc)
7575
xbps_object_release(providers);
76-
return -ENOMEM;
76+
return xbps_error_oom();
7777
}
7878

7979
if (alloc)

lib/transaction_check_shlibs.c

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ shlib_entry_get(struct shlib_ctx *ctx, const char *name)
7676
return res;
7777
res = calloc(1, sizeof(*res));
7878
if (!res) {
79-
xbps_error_printf("out of memory\n");
80-
errno = ENOMEM;
79+
xbps_error_oom();
8180
return NULL;
8281
}
8382
res->name = name;
@@ -109,16 +108,12 @@ collect_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs)
109108

110109
// can't set null values to xbps_dictionary so just use one boolean
111110
placeholder = xbps_bool_create(true);
112-
if (!placeholder) {
113-
xbps_error_printf("out of memory\n");
114-
return -ENOMEM;
115-
}
111+
if (!placeholder)
112+
return xbps_error_oom();
116113

117114
ctx->seen = xbps_dictionary_create();
118-
if (!ctx->seen) {
119-
xbps_error_printf("out of memory\n");
120-
return -ENOMEM;
121-
}
115+
if (!ctx->seen)
116+
return xbps_error_oom();
122117

123118
for (unsigned int i = 0; i < xbps_array_count(pkgs); i++) {
124119
const char *pkgname;
@@ -131,10 +126,8 @@ collect_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs)
131126
xbps_error_printf("invalid package: missing `pkgname` property\n");
132127
return -EINVAL;
133128
}
134-
if (!xbps_dictionary_set(ctx->seen, pkgname, placeholder)) {
135-
xbps_error_printf("out of memory\n");
136-
return -ENOMEM;
137-
}
129+
if (!xbps_dictionary_set(ctx->seen, pkgname, placeholder))
130+
return xbps_error_oom();
138131

139132
if (xbps_transaction_pkg_type(pkgd) == XBPS_TRANS_REMOVE)
140133
continue;
@@ -148,10 +141,8 @@ collect_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs)
148141
}
149142

150143
iter = xbps_dictionary_iterator(ctx->xhp->pkgdb);
151-
if (!iter) {
152-
xbps_error_printf("out of memory\n");
153-
return -ENOMEM;
154-
}
144+
if (!iter)
145+
return xbps_error_oom();
155146

156147
while ((obj = xbps_object_iterator_next(iter))) {
157148
xbps_array_t array;
@@ -210,18 +201,14 @@ check_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs)
210201
missing = xbps_xasprintf(
211202
"%s: broken, unresolvable shlib `%s'",
212203
pkgver, shlib);
213-
if (!xbps_array_add_cstring_nocopy(ctx->missing, missing)) {
214-
xbps_error_printf("out of memory\n");
215-
return -ENOMEM;
216-
}
204+
if (!xbps_array_add_cstring_nocopy(ctx->missing, missing))
205+
return xbps_error_oom();
217206
}
218207
}
219208

220209
iter = xbps_dictionary_iterator(ctx->xhp->pkgdb);
221-
if (!iter) {
222-
xbps_error_printf("out of memory\n");
223-
return -ENOMEM;
224-
}
210+
if (!iter)
211+
return xbps_error_oom();
225212

226213
while ((obj = xbps_object_iterator_next(iter))) {
227214
xbps_array_t array;
@@ -254,10 +241,8 @@ check_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs)
254241
missing = xbps_xasprintf(
255242
"%s: broken, unresolvable shlib `%s'", pkgver,
256243
shlib);
257-
if (!xbps_array_add_cstring_nocopy(ctx->missing, missing)) {
258-
xbps_error_printf("out of memory\n");
259-
return -ENOMEM;
260-
}
244+
if (!xbps_array_add_cstring_nocopy(ctx->missing, missing))
245+
return xbps_error_oom();
261246
}
262247
}
263248

0 commit comments

Comments
 (0)