This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=6e8fa2892262d34a441a32a78eae9ccbc7fa1241 commit 6e8fa2892262d34a441a32a78eae9ccbc7fa1241 Author: Guillem Jover <[email protected]> AuthorDate: Sun Nov 5 00:49:42 2023 +0100 Reduce variables scope Warned-by: cppcheck (variableScope) Changelog: internal --- dselect/pkgcmds.cc | 2 +- dselect/pkgdisplay.cc | 4 ++-- lib/dpkg/t/t-pager.c | 4 +++- src/split/info.c | 5 +++-- src/split/queue.c | 5 +++-- utils/start-stop-daemon.c | 11 +++++++---- utils/update-alternatives.c | 7 ++++--- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/dselect/pkgcmds.cc b/dselect/pkgcmds.cc index 0d21bff4b..9f581d335 100644 --- a/dselect/pkgcmds.cc +++ b/dselect/pkgcmds.cc @@ -105,7 +105,6 @@ void packagelist::setwant(pkgwant nwarg) { int bot; - pkgwant nw; if (modstatdb_get_status() == msdbrw_readonly) { beep(); @@ -119,6 +118,7 @@ packagelist::setwant(pkgwant nwarg) bot= cursorline+1; } else { int top; + pkgwant nw; packagelist *sub = new packagelist(bindings, nullptr); diff --git a/dselect/pkgdisplay.cc b/dselect/pkgdisplay.cc index 2396a85bf..5cc4663a6 100644 --- a/dselect/pkgdisplay.cc +++ b/dselect/pkgdisplay.cc @@ -189,9 +189,9 @@ void packagelist::setwidths() { } void packagelist::redrawtitle() { - int x, y DPKG_ATTR_UNUSED; - if (title_height) { + int x, y DPKG_ATTR_UNUSED; + mywerase(titlewin); mvwaddnstr(titlewin,0,0, recursive ? _("dselect - recursive package listing") : diff --git a/lib/dpkg/t/t-pager.c b/lib/dpkg/t/t-pager.c index 9ce7a2450..d007dde62 100644 --- a/lib/dpkg/t/t-pager.c +++ b/lib/dpkg/t/t-pager.c @@ -45,11 +45,13 @@ test_dup_file(int fd, const char *filename, int flags) static void test_pager_get_exec(void) { - const char *pager, *default_pager; + const char *pager; int origfd = dup(STDOUT_FILENO); /* Test stdout being a tty. */ test_todo_block("environment might not expose controlling terminal") { + const char *default_pager; + test_dup_file(STDOUT_FILENO, "/dev/tty", O_WRONLY); setenv("PAGER", "test-pager", 1); pager = pager_get_exec(); diff --git a/src/split/info.c b/src/split/info.c index eaf610cf3..24c91d81d 100644 --- a/src/split/info.c +++ b/src/split/info.c @@ -265,14 +265,15 @@ int do_info(const char *const *argv) { const char *thisarg; - struct partinfo *pi, ps; - struct dpkg_ar *part; if (!*argv) badusage(_("--%s requires one or more part file arguments"), cipaction->olong); while ((thisarg= *argv++)) { + struct partinfo *pi, ps; + struct dpkg_ar *part; + part = dpkg_ar_open(thisarg); if (!part) ohshite(_("cannot open archive part file '%.250s'"), thisarg); diff --git a/src/split/queue.c b/src/split/queue.c index c9b8847d0..b8d559b94 100644 --- a/src/split/queue.c +++ b/src/split/queue.c @@ -345,12 +345,13 @@ discard_parts(struct partqueue *queue, enum discard_which which, int do_discard(const char *const *argv) { - const char *thisarg; struct partqueue *queue; - struct partqueue *pq; queue = scandepot(); if (*argv) { + const char *thisarg; + struct partqueue *pq; + for (pq= queue; pq; pq= pq->nextinqueue) if (pq->info.md5sum) mustgetpartinfo(pq->info.filename,&pq->info); diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 4d6dc34de..a3e91f41b 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -665,7 +665,6 @@ wait_for_notify(int fd) { struct timespec startat, now, elapsed, timeout, timeout_orig; fd_set fdrs; - int rc; timeout.tv_sec = notify_timeout; timeout.tv_nsec = 0; @@ -674,6 +673,8 @@ wait_for_notify(int fd) timespec_gettime(&startat); while (timeout.tv_sec >= 0 && timeout.tv_nsec >= 0) { + int rc; + FD_ZERO(&fdrs); FD_SET(fd, &fdrs); @@ -2452,9 +2453,9 @@ do_procinit(void) enum status_code prog_status = STATUS_DEAD; while ((count = pstat_getproc(pst, sizeof(pst[0]), 10, idx)) > 0) { - enum status_code pid_status; - for (i = 0; i < count; i++) { + enum status_code pid_status; + pid_status = pid_check(pst[i].pst_pid); if (pid_status < prog_status) prog_status = pid_status; @@ -2755,12 +2756,14 @@ static bool do_stop_timeout(int timeout, int *n_killed, int *n_notkilled) { struct timespec stopat, before, after, interval, maxinterval; - int rc, ratio; + int ratio; timespec_gettime(&stopat); stopat.tv_sec += timeout; ratio = 1; for (;;) { + int rc; + timespec_gettime(&before); if (timespec_cmp(&before, &stopat, >)) return false; diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c index 760c16414..30cf153bb 100644 --- a/utils/update-alternatives.c +++ b/utils/update-alternatives.c @@ -501,8 +501,6 @@ make_path(const char *pathname, mode_t mode) static void LIBCOMPAT_ATTR_PRINTF(1) log_msg(const char *fmt, ...) { - va_list args; - if (fh_log == NULL) { fh_log = fopen(log_file, "a"); if (fh_log == NULL && errno == ENOENT) { @@ -520,6 +518,7 @@ log_msg(const char *fmt, ...) } if (fh_log) { + va_list args; char timestamp[64]; time_t now; struct tm tm; @@ -1812,7 +1811,7 @@ alternative_select_choice(struct alternative *a) char *ret, selection[_POSIX_PATH_MAX]; struct fileset *best, *fs; int n_choices; - int len, idx; + int len; n_choices = alternative_choices_count(a); current = alternative_get_current(a); @@ -1824,6 +1823,8 @@ alternative_select_choice(struct alternative *a) len = max(len, (int)strlen(fs->master_file) + 1); for (;;) { + int idx; + pr(P_("There is %d choice for the alternative %s (providing %s).", "There are %d choices for the alternative %s (providing %s).", n_choices), n_choices, a->master_name, a->master_link); -- Dpkg.Org's dpkg

