Skip to content

Commit 4a69184

Browse files
committed
lib: remove dead assignments
1 parent d67aebc commit 4a69184

5 files changed

Lines changed: 36 additions & 43 deletions

File tree

include/xbps.h.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,16 @@ int xbps_error_errno(int r, const char *fmt, ...) PRINTF_LIKE(2, 3);
777777
xbps_error_errno(ENOMEM, "%s:%d %s: out of memory\n", __FILE__, \
778778
__LINE__, __func__)
779779

780+
/**
781+
* @brief Log and abort for code that should be unreachable.
782+
*/
783+
#define xbps_unreachable() \
784+
do { \
785+
xbps_error_printf("%s:%d %s: code should not be reached\n", \
786+
__FILE__, __LINE__, __func__); \
787+
abort(); \
788+
} while (0)
789+
780790
/**@}*/
781791

782792
/** @addtogroup configure */

lib/package_unpack.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ unpack_archive(struct xbps_handle *xhp,
8888
{
8989
xbps_dictionary_t binpkg_filesd, pkg_filesd, obsd;
9090
xbps_array_t array, obsoletes;
91-
xbps_trans_type_t ttype;
9291
const struct stat *entry_statp;
9392
struct stat st;
9493
struct xbps_unpack_cb_data xucd;
@@ -97,17 +96,16 @@ unpack_archive(struct xbps_handle *xhp,
9796
const char *entry_pname, *pkgname;
9897
const char *file;
9998
int ar_rv, rv, error, entry_type, flags;
100-
bool preserve, update, file_exists, keep_conf_file;
99+
bool preserve, file_exists, keep_conf_file;
101100
bool skip_extract, force, xucd_stats;
102101
uid_t euid;
103102

104103
binpkg_filesd = pkg_filesd = NULL;
105-
force = preserve = update = file_exists = false;
104+
force = preserve = false;
106105
xucd_stats = false;
107-
ar_rv = rv = error = entry_type = flags = 0;
106+
ar_rv = rv = error = 0;
108107

109108
xbps_dictionary_get_bool(pkg_repod, "preserve", &preserve);
110-
ttype = xbps_transaction_pkg_type(pkg_repod);
111109

112110
memset(&xucd, 0, sizeof(xucd));
113111

@@ -121,10 +119,6 @@ unpack_archive(struct xbps_handle *xhp,
121119
force = true;
122120
}
123121

124-
if (ttype == XBPS_TRANS_UPDATE) {
125-
update = true;
126-
}
127-
128122
/*
129123
* Remove obsolete files.
130124
*/
@@ -169,7 +163,6 @@ unpack_archive(struct xbps_handle *xhp,
169163
break;
170164

171165
entry_pname = archive_entry_pathname(entry);
172-
entry_size = archive_entry_size(entry);
173166

174167
if (strcmp("./INSTALL", entry_pname) == 0 ||
175168
strcmp("./REMOVE", entry_pname) == 0 ||

lib/transaction_commit.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <stdlib.h>
2929
#include <string.h>
3030
#include <errno.h>
31-
#include <ctype.h>
3231
#include <unistd.h>
3332
#include <limits.h>
3433
#include <locale.h>
@@ -109,7 +108,6 @@ xbps_transaction_commit(struct xbps_handle *xhp)
109108
xbps_trans_type_t ttype;
110109
const char *pkgver = NULL, *pkgname = NULL;
111110
int rv = 0;
112-
bool update, replaced;
113111

114112
setlocale(LC_ALL, "");
115113

@@ -220,6 +218,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
220218
xbps_dictionary_t dict;
221219
xbps_data_t script = NULL;
222220
const char *pkgdb_pkgver;
221+
bool update;
223222

224223
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
225224
xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
@@ -232,7 +231,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
232231
}
233232

234233
if ((pkgdb_pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) {
235-
replaced = false;
234+
bool replaced = false;
236235
xbps_dictionary_get_bool(obj, "replaced", &replaced);
237236
if (replaced) {
238237
continue;
@@ -311,14 +310,14 @@ xbps_transaction_commit(struct xbps_handle *xhp)
311310

312311
ttype = xbps_transaction_pkg_type(obj);
313312
if (ttype == XBPS_TRANS_REMOVE) {
313+
bool replaced = false;
314+
bool update = false;
314315
/*
315316
* Remove package.
316317
*/
317-
update = false;
318318
xbps_dictionary_get_bool(obj, "remove-and-update", &update);
319-
replaced = false;
320319
xbps_dictionary_get_bool(obj, "replaced", &replaced);
321-
if (((pkgdb_pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) && replaced) {
320+
if (replaced && !xbps_pkgdb_get_pkg(xhp, pkgname)) {
322321
continue;
323322
}
324323
rv = xbps_remove_pkg(xhp, pkgver, update);
@@ -410,16 +409,16 @@ xbps_transaction_commit(struct xbps_handle *xhp)
410409
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL);
411410

412411
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
412+
bool update;
413+
413414
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
414415
ttype = xbps_transaction_pkg_type(obj);
415416
if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) {
416417
xbps_dbg_printf("%s: skipping configuration for "
417418
"%s: %d\n", __func__, pkgver, ttype);
418419
continue;
419420
}
420-
update = false;
421-
if (ttype == XBPS_TRANS_UPDATE)
422-
update = true;
421+
update = ttype == XBPS_TRANS_UPDATE;
423422

424423
rv = xbps_configure_pkg(xhp, pkgver, false, update);
425424
if (rv != 0) {

lib/transaction_fetch.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include <errno.h>
2828
#include <limits.h>
29-
#include <stdlib.h>
3029
#include <string.h>
3130
#include <unistd.h>
3231

@@ -122,31 +121,28 @@ download_binpkg(struct xbps_handle *xhp, xbps_dictionary_t repo_pkgd)
122121
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD, 0, pkgver,
123122
"Downloading `%s' signature (from `%s')...", pkgver, repoloc);
124123

125-
if ((rv = xbps_fetch_file(xhp, buf, NULL)) == -1) {
124+
if (xbps_fetch_file(xhp, buf, NULL) == -1) {
126125
rv = fetchLastErrCode ? fetchLastErrCode : errno;
127126
fetchstr = xbps_fetch_error_string();
128127
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL, rv,
129128
pkgver, "[trans] failed to download `%s' signature from `%s': %s",
130129
pkgver, repoloc, fetchstr ? fetchstr : strerror(rv));
131130
return rv;
132131
}
133-
rv = 0;
134132

135133
*sigsuffix = '\0';
136134

137135
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD, 0, pkgver,
138136
"Downloading `%s' package (from `%s')...", pkgver, repoloc);
139137

140-
if ((rv = xbps_fetch_file_sha256(xhp, buf, NULL, digest,
141-
sizeof digest)) == -1) {
138+
if (xbps_fetch_file_sha256(xhp, buf, NULL, digest, sizeof digest) == -1) {
142139
rv = fetchLastErrCode ? fetchLastErrCode : errno;
143140
fetchstr = xbps_fetch_error_string();
144141
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL, rv,
145142
pkgver, "[trans] failed to download `%s' package from `%s': %s",
146143
pkgver, repoloc, fetchstr ? fetchstr : strerror(rv));
147144
return rv;
148145
}
149-
rv = 0;
150146

151147
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgver,
152148
"%s: verifying RSA signature...", pkgver);
@@ -165,6 +161,7 @@ download_binpkg(struct xbps_handle *xhp, xbps_dictionary_t repo_pkgd)
165161
* If digest is not set, binary package was not downloaded,
166162
* i.e. 304 not modified, verify by file instead.
167163
*/
164+
rv = 0;
168165
if (fetchLastErrCode == FETCH_UNCHANGED) {
169166
*sigsuffix = '\0';
170167
if (!xbps_verify_file_signature(repo, buf)) {

lib/transaction_ops.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,14 @@ xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg, bool force
392392
rdeps = NULL;
393393
}
394394
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
395+
char pkgname[XBPS_NAME_SIZE];
395396
const char *pkgver = NULL;
396-
char pkgname[XBPS_NAME_SIZE] = {0};
397397

398-
if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
399-
rv = EINVAL;
400-
break;
401-
}
402-
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
403-
rv = EINVAL;
404-
break;
405-
}
398+
if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver))
399+
xbps_unreachable();
400+
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
401+
xbps_unreachable();
402+
406403
rv = trans_find_pkg(xhp, pkgname, false);
407404
xbps_dbg_printf("%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
408405
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {
@@ -442,17 +439,14 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg, bool forc
442439
rdeps = NULL;
443440
}
444441
for (unsigned int i = 0; i < xbps_array_count(rdeps); i++) {
442+
char pkgname[XBPS_NAME_SIZE];
445443
const char *pkgver = NULL;
446-
char pkgname[XBPS_NAME_SIZE] = {0};
447444

448-
if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver)) {
449-
rv = EINVAL;
450-
break;
451-
}
452-
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) {
453-
rv = EINVAL;
454-
break;
455-
}
445+
if (!xbps_array_get_cstring_nocopy(rdeps, i, &pkgver))
446+
xbps_unreachable();
447+
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
448+
xbps_unreachable();
449+
456450
rv = trans_find_pkg(xhp, pkgname, false);
457451
xbps_dbg_printf("%s: trans_find_pkg %s: %d\n", __func__, pkgver, rv);
458452
if (rv && rv != ENOENT && rv != EEXIST && rv != ENODEV) {

0 commit comments

Comments
 (0)