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=a33b5d71972b40304b38cde01f1c8fe4d67cd0b1

commit a33b5d71972b40304b38cde01f1c8fe4d67cd0b1
Author: Guillem Jover <[email protected]>
AuthorDate: Tue Feb 14 02:20:11 2023 +0100

    libdpkg: Reduce variables scope
    
    Warned-by: cppcheck
---
 lib/dpkg/compress.c      |  3 ++-
 lib/dpkg/db-fsys-files.c | 10 ++++++----
 lib/dpkg/dbmodify.c      |  4 +++-
 lib/dpkg/dump.c          |  5 +++--
 lib/dpkg/fields.c        | 37 +++++++++++++++++++++++++------------
 lib/dpkg/parse.c         |  3 ++-
 lib/dpkg/string.c        |  3 ++-
 lib/dpkg/trigdeferred.c  |  4 ++--
 lib/dpkg/triglib.c       |  5 +++--
 9 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/lib/dpkg/compress.c b/lib/dpkg/compress.c
index e56f6c1a4..adf26ea76 100644
--- a/lib/dpkg/compress.c
+++ b/lib/dpkg/compress.c
@@ -65,10 +65,11 @@ static void
 fd_fd_filter(struct command *cmd, int fd_in, int fd_out, const char *delenv[])
 {
        pid_t pid;
-       int i;
 
        pid = subproc_fork();
        if (pid == 0) {
+               int i;
+
                if (fd_in != 0) {
                        m_dup2(fd_in, 0);
                        close(fd_in);
diff --git a/lib/dpkg/db-fsys-files.c b/lib/dpkg/db-fsys-files.c
index 7cdb998af..abdd05109 100644
--- a/lib/dpkg/db-fsys-files.c
+++ b/lib/dpkg/db-fsys-files.c
@@ -78,8 +78,6 @@ void
 ensure_packagefiles_available(struct pkginfo *pkg)
 {
   const char *filelistfile;
-  struct fsys_namenode_list **lendp;
-  char *loaded_list_end, *thisline, *nextline, *ptr;
   struct varbuf buf = VARBUF_INIT;
   struct dpkg_error err = DPKG_ERROR_INIT;
 
@@ -117,12 +115,16 @@ ensure_packagefiles_available(struct pkginfo *pkg)
   }
 
   if (buf.used) {
+    struct fsys_namenode_list **lendp;
+    char *loaded_list_end, *thisline;
+
     loaded_list_end = buf.buf + buf.used;
 
     lendp = &pkg->files;
     thisline = buf.buf;
     while (thisline < loaded_list_end) {
       struct fsys_namenode *namenode;
+      char *nextline, *ptr;
 
       ptr = memchr(thisline, '\n', loaded_list_end - thisline);
       if (ptr == NULL)
@@ -249,7 +251,6 @@ pkg_files_optimize_load(struct pkg_array *array)
 
 void ensure_allinstfiles_available(void) {
   struct pkg_array array;
-  struct pkginfo *pkg;
   struct progress progress;
   int i;
 
@@ -266,7 +267,8 @@ void ensure_allinstfiles_available(void) {
   pkg_files_optimize_load(&array);
 
   for (i = 0; i < array.n_pkgs; i++) {
-    pkg = array.pkgs[i];
+    struct pkginfo *pkg = array.pkgs[i];
+
     ensure_packagefiles_available(pkg);
 
     if (saidread == PKG_FILESDB_LOAD_INPROGRESS)
diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c
index b95bb77a8..f38beceee 100644
--- a/lib/dpkg/dbmodify.c
+++ b/lib/dpkg/dbmodify.c
@@ -79,7 +79,7 @@ static int ulist_select(const struct dirent *de) {
 
 static void cleanupdates(void) {
   struct dirent **cdlist;
-  int cdn, i;
+  int cdn;
 
   parsedb(statusfile, pdb_parse_status, NULL);
 
@@ -97,6 +97,8 @@ static void cleanupdates(void) {
   }
 
   if (cdn) {
+    int i;
+
     for (i=0; i<cdn; i++) {
       varbuf_rollback(&updatefn_state);
       varbuf_add_str(&updatefn, cdlist[i]->d_name);
diff --git a/lib/dpkg/dump.c b/lib/dpkg/dump.c
index 05018baaf..b27e5db90 100644
--- a/lib/dpkg/dump.c
+++ b/lib/dpkg/dump.c
@@ -499,8 +499,6 @@ writedb_stanzas(FILE *fp, const char *filename, enum 
writedb_flags flags)
   static char writebuf[8192];
 
   struct pkg_array array;
-  struct pkginfo *pkg;
-  struct pkgbin *pkgbin;
   const char *which;
   struct varbuf vb = VARBUF_INIT;
   int i;
@@ -514,6 +512,9 @@ writedb_stanzas(FILE *fp, const char *filename, enum 
writedb_flags flags)
   pkg_array_sort(&array, pkg_sorter_by_nonambig_name_arch);
 
   for (i = 0; i < array.n_pkgs; i++) {
+    struct pkginfo *pkg;
+    struct pkgbin *pkgbin;
+
     pkg = array.pkgs[i];
     pkgbin = (flags & wdb_dump_available) ? &pkg->available : &pkg->installed;
 
diff --git a/lib/dpkg/fields.c b/lib/dpkg/fields.c
index 2210e3c23..04127512b 100644
--- a/lib/dpkg/fields.c
+++ b/lib/dpkg/fields.c
@@ -355,14 +355,16 @@ f_conffiles(struct pkginfo *pkg, struct pkgbin *pkgbin,
 {
   static const char obsolete_str[]= "obsolete";
   static const char remove_on_upgrade_str[] = "remove-on-upgrade";
-  struct conffile **lastp, *newlink;
-  const char *endent, *endfn, *hashstart;
-  int c, namelen, hashlen;
-  bool obsolete, remove_on_upgrade;
-  char *newptr;
+  struct conffile **lastp;
 
   lastp = &pkgbin->conffiles;
   while (*value) {
+    struct conffile *newlink;
+    const char *endent, *endfn, *hashstart;
+    char *newptr;
+    int c, namelen, hashlen;
+    bool obsolete, remove_on_upgrade;
+
     c= *value++;
     if (c == '\n') continue;
     if (c != ' ')
@@ -415,14 +417,10 @@ f_dependency(struct pkginfo *pkg, struct pkgbin *pkgbin,
              struct parsedb_state *ps,
              const char *value, const struct fieldinfo *fip)
 {
-  char c1, c2;
   const char *p, *emsg;
-  const char *depnamestart, *versionstart;
-  int depnamelength, versionlength;
   static struct varbuf depname, version;
 
-  struct dependency *dyp, **ldypp;
-  struct deppossi *dop, **ldopp;
+  struct dependency **ldypp;
 
   /* Empty fields are ignored. */
   if (!*value)
@@ -435,6 +433,9 @@ f_dependency(struct pkginfo *pkg, struct pkgbin *pkgbin,
 
    /* Loop creating new struct dependency's. */
   for (;;) {
+    struct deppossi **ldopp;
+    struct dependency *dyp;
+
     dyp = nfmalloc(sizeof(*dyp));
     /* Set this to NULL for now, as we don't know what our real
      * struct pkginfo address (in the database) is going to be yet. */
@@ -445,6 +446,10 @@ f_dependency(struct pkginfo *pkg, struct pkgbin *pkgbin,
 
     /* Loop creating new struct deppossi's. */
     for (;;) {
+      const char *depnamestart;
+      int depnamelength;
+      struct deppossi *dop;
+
       depnamestart= p;
       /* Skip over package name characters. */
       while (*p && !c_isspace(*p) && *p != ':' && *p != '(' && *p != ',' &&
@@ -527,11 +532,17 @@ f_dependency(struct pkginfo *pkg, struct pkgbin *pkgbin,
 
       /* See if we have a versioned relation. */
       if (*p == '(') {
+        char c1;
+        const char *versionstart;
+        int versionlength;
+
         p++;
         while (c_isspace(*p))
           p++;
         c1= *p;
         if (c1 == '<' || c1 == '>') {
+          char c2;
+
           c2= *++p;
           dop->verrel = (c1 == '<') ? DPKG_RELATION_LT : DPKG_RELATION_GT;
           if (c2 == '=') {
@@ -685,7 +696,7 @@ f_trigpend(struct pkginfo *pend, struct pkgbin *pkgbin,
            struct parsedb_state *ps,
            const char *value, const struct fieldinfo *fip)
 {
-  const char *word, *emsg;
+  const char *word;
 
   if (ps->flags & pdb_rejectstatus)
     parse_error(ps,
@@ -693,6 +704,8 @@ f_trigpend(struct pkginfo *pend, struct pkgbin *pkgbin,
                 fip->name);
 
   while ((word = scan_word(&value))) {
+    const char *emsg;
+
     emsg = trig_name_is_illegal(word);
     if (emsg)
       parse_error(ps,
@@ -710,7 +723,6 @@ f_trigaw(struct pkginfo *aw, struct pkgbin *pkgbin,
          const char *value, const struct fieldinfo *fip)
 {
   const char *word;
-  struct pkginfo *pend;
 
   if (ps->flags & pdb_rejectstatus)
     parse_error(ps,
@@ -718,6 +730,7 @@ f_trigaw(struct pkginfo *aw, struct pkgbin *pkgbin,
                 fip->name);
 
   while ((word = scan_word(&value))) {
+    struct pkginfo *pend;
     struct dpkg_error err;
 
     pend = pkg_spec_parse_pkg(word, &err);
diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c
index 9ff3b686f..b9ed596d7 100644
--- a/lib/dpkg/parse.c
+++ b/lib/dpkg/parse.c
@@ -394,7 +394,6 @@ parse_find_pkg_slot(struct parsedb_state *ps,
                     struct pkginfo *new_pkg, struct pkgbin *new_pkgbin)
 {
   struct pkgset *db_set;
-  struct pkginfo *db_pkg;
 
   db_set = parse_find_set_slot(ps, new_pkg, new_pkgbin);
 
@@ -432,6 +431,8 @@ parse_find_pkg_slot(struct parsedb_state *ps,
     /* If we are doing an update, from the log or a new package, then
      * handle cross-grades. */
     if (pkgset_installed_instances(db_set) == 1) {
+      struct pkginfo *db_pkg;
+
       db_pkg = pkg_hash_get_singleton(db_set);
 
       if (db_pkg->installed.multiarch == PKG_MULTIARCH_SAME &&
diff --git a/lib/dpkg/string.c b/lib/dpkg/string.c
index 0428f0f35..de1829769 100644
--- a/lib/dpkg/string.c
+++ b/lib/dpkg/string.c
@@ -33,10 +33,11 @@ str_concat(char *dst, ...)
 {
        va_list args;
        const char *src;
-       size_t len;
 
        va_start(args, dst);
        while ((src = va_arg(args, const char *))) {
+               size_t len;
+
                len = strlen(src);
                memcpy(dst, src, len);
                dst += len;
diff --git a/lib/dpkg/trigdeferred.c b/lib/dpkg/trigdeferred.c
index 6e49e2542..d1facd59a 100644
--- a/lib/dpkg/trigdeferred.c
+++ b/lib/dpkg/trigdeferred.c
@@ -249,8 +249,6 @@ trigdef_parse(void)
 void
 trigdef_process_done(void)
 {
-       int r;
-
        if (old_deferred) {
                if (ferror(old_deferred))
                        ohshite(_("error reading triggers deferred file 
'%.250s'"),
@@ -260,6 +258,8 @@ trigdef_process_done(void)
        }
 
        if (trig_new_deferred) {
+               int r;
+
                if (ferror(trig_new_deferred))
                        ohshite(_("unable to write new triggers deferred "
                                  "file '%.250s'"), newfn.buf);
diff --git a/lib/dpkg/triglib.c b/lib/dpkg/triglib.c
index e03554b99..c94f1be33 100644
--- a/lib/dpkg/triglib.c
+++ b/lib/dpkg/triglib.c
@@ -101,7 +101,6 @@ void
 trig_clear_awaiters(struct pkginfo *notpend)
 {
        struct trigaw *ta;
-       struct pkginfo *aw;
 
        if (notpend->trigpend_head)
                internerr("package %s has pending triggers",
@@ -110,6 +109,8 @@ trig_clear_awaiters(struct pkginfo *notpend)
        ta = notpend->othertrigaw_head;
        notpend->othertrigaw_head = NULL;
        for (; ta; ta = ta->samepend_next) {
+               struct pkginfo *aw;
+
                aw = ta->aw;
                if (!aw)
                        continue;
@@ -317,7 +318,6 @@ static void
 trk_explicit_activate_awaiter(struct pkginfo *aw)
 {
        char buf[1024];
-       struct pkginfo *pend;
 
        if (!trk_explicit_f)
                return;
@@ -327,6 +327,7 @@ trk_explicit_activate_awaiter(struct pkginfo *aw)
                        trk_explicit_fn.buf);
 
        while (trk_explicit_fgets(buf, sizeof(buf)) >= 0) {
+               struct pkginfo *pend;
                struct dpkg_error err;
                enum trig_options opts;
 

-- 
Dpkg.Org's dpkg

Reply via email to