This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=e29648778ccd54ff834c3581b460542fdb766d44

commit e29648778ccd54ff834c3581b460542fdb766d44
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Sat Nov 17 20:35:54 2018 +0100

    When allocating use the variable instead of the type in sizeof()
    
    This makes it easier to guarantee we use the correct size for the
    involved variable.
---
 debian/changelog            | 1 +
 dpkg-split/join.c           | 4 ++--
 dpkg-split/queue.c          | 8 ++++----
 lib/compat/scandir.c        | 6 +++---
 lib/dpkg/db-fsys-divert.c   | 4 ++--
 lib/dpkg/db-fsys-override.c | 2 +-
 lib/dpkg/ehandle.c          | 6 +++---
 lib/dpkg/fields.c           | 8 ++++----
 lib/dpkg/fsys-hash.c        | 4 ++--
 lib/dpkg/fsys-iter.c        | 2 +-
 lib/dpkg/log.c              | 2 +-
 lib/dpkg/parse.c            | 2 +-
 lib/dpkg/pkg-files.c        | 2 +-
 lib/dpkg/pkg-hash.c         | 6 +++---
 lib/dpkg/treewalk.c         | 4 ++--
 src/archives.c              | 2 +-
 src/enquiry.c               | 2 +-
 src/errors.c                | 2 +-
 src/main.c                  | 2 +-
 src/perpkgstate.c           | 2 +-
 src/remove.c                | 2 +-
 src/unpack.c                | 8 ++++----
 22 files changed, 41 insertions(+), 40 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 745a79025..c056e6a7e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -109,6 +109,7 @@ dpkg (1.19.3) UNRELEASED; urgency=medium
     - dpkg: Split trigger processing types into required, try-queued and
       try-deferred.
     - dpkg-query: Rename variable to avoid shadowing a local function.
+    - When allocating use the variable instead of the type in sizeof().
   * Build system:
     - get-version: Use a format string with printf.
     - run-script: Use $() instead of deprecated ``.
diff --git a/dpkg-split/join.c b/dpkg-split/join.c
index 305b9d41e..40afb378e 100644
--- a/dpkg-split/join.c
+++ b/dpkg-split/join.c
@@ -109,7 +109,7 @@ do_join(const char *const *argv)
     badusage(_("--%s requires one or more part file arguments"),
              cipaction->olong);
   while ((thisarg= *argv++)) {
-    pq= nfmalloc(sizeof(struct partqueue));
+    pq = nfmalloc(sizeof(*pq));
 
     mustgetpartinfo(thisarg,&pq->info);
 
@@ -122,7 +122,7 @@ do_join(const char *const *argv)
   if (refi == NULL)
     internerr("empty deb part queue");
 
-  partlist= nfmalloc(sizeof(struct partinfo*)*refi->maxpartn);
+  partlist = nfmalloc(sizeof(*partlist) * refi->maxpartn);
   for (i = 0; i < refi->maxpartn; i++)
     partlist[i] = NULL;
   for (pq= queue; pq; pq= pq->nextinqueue) {
diff --git a/dpkg-split/queue.c b/dpkg-split/queue.c
index 1ef083ea5..6f9688035 100644
--- a/dpkg-split/queue.c
+++ b/dpkg-split/queue.c
@@ -99,7 +99,7 @@ scandepot(void)
     char *p;
 
     if (de->d_name[0] == '.') continue;
-    pq= nfmalloc(sizeof(struct partqueue));
+    pq = nfmalloc(sizeof(*pq));
     pq->info.fmtversion.major = 0;
     pq->info.fmtversion.minor = 0;
     pq->info.package = NULL;
@@ -148,7 +148,7 @@ do_auto(const char *const *argv)
   if (partfile == NULL || *argv)
     badusage(_("--auto requires exactly one part file argument"));
 
-  refi= nfmalloc(sizeof(struct partqueue));
+  refi = nfmalloc(sizeof(*refi));
   part = dpkg_ar_open(partfile);
   if (!part)
     ohshite(_("unable to read part file '%.250s'"), partfile);
@@ -161,14 +161,14 @@ do_auto(const char *const *argv)
   dpkg_ar_close(part);
 
   queue = scandepot();
-  partlist= nfmalloc(sizeof(struct partinfo*)*refi->maxpartn);
+  partlist = nfmalloc(sizeof(*partlist) * refi->maxpartn);
   for (i = 0; i < refi->maxpartn; i++)
     partlist[i] = NULL;
   for (pq= queue; pq; pq= pq->nextinqueue) {
     struct partinfo *npi, *pi = &pq->info;
 
     if (!partmatches(pi,refi)) continue;
-    npi= nfmalloc(sizeof(struct partinfo));
+    npi = nfmalloc(sizeof(*npi));
     mustgetpartinfo(pi->filename,npi);
     addtopartlist(partlist,npi,refi);
   }
diff --git a/lib/compat/scandir.c b/lib/compat/scandir.c
index 4765d7dcb..8771de093 100644
--- a/lib/compat/scandir.c
+++ b/lib/compat/scandir.c
@@ -72,13 +72,13 @@ scandir(const char *dir, struct dirent ***namelist,
                                avail *= 2;
                        else
                                avail = 20;
-                       newlist = realloc(list, avail * sizeof(struct dirent 
*));
+                       newlist = realloc(list, avail * sizeof(*newlist));
                        if (!newlist)
                                return cleanup(d, list, used);
                        list = newlist;
                }
 
-               m = malloc(sizeof(struct dirent) + strlen(e->d_name));
+               m = malloc(sizeof(*m) + strlen(e->d_name));
                if (!m)
                        return cleanup(d, list, used);
                *m = *e;
@@ -91,7 +91,7 @@ scandir(const char *dir, struct dirent ***namelist,
        closedir(d);
 
        if (list != NULL && cmp != NULL)
-               qsort(list, used, sizeof(struct dirent *), cmp);
+               qsort(list, used, sizeof(list[0]), cmp);
 
        *namelist = list;
 
diff --git a/lib/dpkg/db-fsys-divert.c b/lib/dpkg/db-fsys-divert.c
index 775662382..b0edd1805 100644
--- a/lib/dpkg/db-fsys-divert.c
+++ b/lib/dpkg/db-fsys-divert.c
@@ -101,8 +101,8 @@ ensure_diversions(void)
        debug(dbg_general, "%s: new, (re)loading", __func__);
 
        while (fgets_checked(linebuf, sizeof(linebuf), file, diversionsname) >= 
0) {
-               oicontest = nfmalloc(sizeof(struct diversion));
-               oialtname = nfmalloc(sizeof(struct diversion));
+               oicontest = nfmalloc(sizeof(*oicontest));
+               oialtname = nfmalloc(sizeof(*oialtname));
 
                oialtname->camefrom = findnamenode(linebuf, 0);
                oialtname->useinstead = NULL;
diff --git a/lib/dpkg/db-fsys-override.c b/lib/dpkg/db-fsys-override.c
index 10a8a273d..8da3afc29 100644
--- a/lib/dpkg/db-fsys-override.c
+++ b/lib/dpkg/db-fsys-override.c
@@ -184,7 +184,7 @@ ensure_statoverrides(enum statdb_parse_flags flags)
 
        thisline = loaded_list;
        while (thisline < loaded_list_end) {
-               fso = nfmalloc(sizeof(struct file_stat));
+               fso = nfmalloc(sizeof(*fso));
 
                ptr = memchr(thisline, '\n', loaded_list_end - thisline);
                if (ptr == NULL)
diff --git a/lib/dpkg/ehandle.c b/lib/dpkg/ehandle.c
index ae3b46aad..81ce47e31 100644
--- a/lib/dpkg/ehandle.c
+++ b/lib/dpkg/ehandle.c
@@ -135,7 +135,7 @@ error_context_new(void)
 {
   struct error_context *necp;
 
-  necp = malloc(sizeof(struct error_context));
+  necp = malloc(sizeof(*necp));
   if (!necp)
     ohshite(_("out of memory for new error context"));
   necp->next= econtext;
@@ -311,7 +311,7 @@ void push_checkpoint(int mask, int value) {
   struct cleanup_entry *cep;
   int i;
 
-  cep = malloc(sizeof(struct cleanup_entry) + sizeof(char *));
+  cep = malloc(sizeof(*cep) + sizeof(void *));
   if (cep == NULL) {
     onerr_abort++;
     ohshite(_("out of memory for new cleanup entry"));
@@ -336,7 +336,7 @@ cleanup_entry_new(void (*call1)(int argc, void **argv), int 
mask1,
 
   onerr_abort++;
 
-  cep = malloc(sizeof(struct cleanup_entry) + sizeof(char *) * (nargs + 1));
+  cep = malloc(sizeof(*cep) + sizeof(void *) * (nargs + 1));
   if (!cep) {
     if (nargs > array_count(emergency.args))
       ohshite(_("out of memory for new cleanup entry with many arguments"));
diff --git a/lib/dpkg/fields.c b/lib/dpkg/fields.c
index cfa1075b2..39044e2a5 100644
--- a/lib/dpkg/fields.c
+++ b/lib/dpkg/fields.c
@@ -138,7 +138,7 @@ f_archives(struct pkginfo *pkg, struct pkgbin *pkgbin,
         parse_error(ps,
                     _("too many values in archive details field '%s' "
                       "(compared to others)"), fip->name);
-      fdp = nfmalloc(sizeof(struct archivedetails));
+      fdp = nfmalloc(sizeof(*fdp));
       fdp->next= NULL;
       fdp->name= fdp->msdosname= fdp->size= fdp->md5sum= NULL;
       *fdpp= fdp;
@@ -360,7 +360,7 @@ f_conffiles(struct pkginfo *pkg, struct pkgbin *pkgbin,
       conffvalue_lastword(value, endfn, endent,
                          &hashstart, &hashlen, &endfn,
                          ps);
-    newlink= nfmalloc(sizeof(struct conffile));
+    newlink = nfmalloc(sizeof(*newlink));
     value = path_skip_slash_dotslash(value);
     namelen= (int)(endfn-value);
     if (namelen <= 0)
@@ -408,7 +408,7 @@ f_dependency(struct pkginfo *pkg, struct pkgbin *pkgbin,
 
    /* Loop creating new struct dependency's. */
   for (;;) {
-    dyp= nfmalloc(sizeof(struct dependency));
+    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. */
     dyp->up = NULL;
@@ -438,7 +438,7 @@ f_dependency(struct pkginfo *pkg, struct pkgbin *pkgbin,
         parse_error(ps,
                     _("'%s' field, invalid package name '%.255s': %s"),
                     fip->name, depname.buf, emsg);
-      dop= nfmalloc(sizeof(struct deppossi));
+      dop = nfmalloc(sizeof(*dop));
       dop->up= dyp;
       dop->ed = pkg_db_find_set(depname.buf);
       dop->next= NULL; *ldopp= dop; ldopp= &dop->next;
diff --git a/lib/dpkg/fsys-hash.c b/lib/dpkg/fsys-hash.c
index 002528c6c..0190d94fb 100644
--- a/lib/dpkg/fsys-hash.c
+++ b/lib/dpkg/fsys-hash.c
@@ -102,7 +102,7 @@ findnamenode(const char *name, enum fnnflags flags)
        if (flags & fnn_nonew)
                return NULL;
 
-       newnode = nfmalloc(sizeof(struct filenamenode));
+       newnode = nfmalloc(sizeof(*newnode));
        newnode->packages = NULL;
        if ((flags & fnn_nocopy) && name > orig_name && name[-1] == '/') {
                newnode->name = name - 1;
@@ -141,7 +141,7 @@ files_db_iter_new(void)
 {
        struct fileiterator *iter;
 
-       iter = m_malloc(sizeof(struct fileiterator));
+       iter = m_malloc(sizeof(*iter));
        iter->namenode = NULL;
        iter->nbinn = 0;
 
diff --git a/lib/dpkg/fsys-iter.c b/lib/dpkg/fsys-iter.c
index aba31aa47..fb47197ef 100644
--- a/lib/dpkg/fsys-iter.c
+++ b/lib/dpkg/fsys-iter.c
@@ -49,7 +49,7 @@ reversefilelist_init(struct reversefilelistiter *iter,
 
        iter->todo = NULL;
        while (files) {
-               newent = m_malloc(sizeof(struct fileinlist));
+               newent = m_malloc(sizeof(*newent));
                newent->namenode = files->namenode;
                newent->next = iter->todo;
                iter->todo = newent;
diff --git a/lib/dpkg/log.c b/lib/dpkg/log.c
index 3079f3ca6..c2221c819 100644
--- a/lib/dpkg/log.c
+++ b/lib/dpkg/log.c
@@ -83,7 +83,7 @@ statusfd_add(int fd)
 
        setcloexec(fd, _("<package status and progress file descriptor>"));
 
-       pipe_new = nfmalloc(sizeof(struct pipef));
+       pipe_new = nfmalloc(sizeof(*pipe_new));
        pipe_new->fd = fd;
        pipe_new->next = status_pipes;
        status_pipes = pipe_new;
diff --git a/lib/dpkg/parse.c b/lib/dpkg/parse.c
index 158e4d11e..14d6192f5 100644
--- a/lib/dpkg/parse.c
+++ b/lib/dpkg/parse.c
@@ -159,7 +159,7 @@ pkg_parse_field(struct parsedb_state *ps, struct 
field_state *fs,
                    fs->fieldlen, fs->fieldstart);
       larpp = &arp->next;
     }
-    arp = nfmalloc(sizeof(struct arbitraryfield));
+    arp = nfmalloc(sizeof(*arp));
     arp->name = nfstrnsave(fs->fieldstart, fs->fieldlen);
     arp->value = nfstrnsave(fs->valuestart, fs->valuelen);
     arp->next = NULL;
diff --git a/lib/dpkg/pkg-files.c b/lib/dpkg/pkg-files.c
index e60134a32..349e63d4f 100644
--- a/lib/dpkg/pkg-files.c
+++ b/lib/dpkg/pkg-files.c
@@ -78,7 +78,7 @@ pkg_files_add_file(struct pkginfo *pkg, struct filenamenode 
*namenode,
                file_tail = &((*file_tail)->next);
 
        /* Create a new node. */
-       newent = nfmalloc(sizeof(struct fileinlist));
+       newent = nfmalloc(sizeof(*newent));
        newent->namenode = namenode;
        newent->next = NULL;
        *file_tail = newent;
diff --git a/lib/dpkg/pkg-hash.c b/lib/dpkg/pkg-hash.c
index 6413b5058..398c20607 100644
--- a/lib/dpkg/pkg-hash.c
+++ b/lib/dpkg/pkg-hash.c
@@ -79,7 +79,7 @@ pkg_db_find_set(const char *inname)
     return *setp;
   }
 
-  new_set = nfmalloc(sizeof(struct pkgset));
+  new_set = nfmalloc(sizeof(*new_set));
   pkgset_blank(new_set);
   new_set->name = nfstrsave(name);
   new_set->next = NULL;
@@ -195,7 +195,7 @@ pkg_db_get_pkg(struct pkgset *set, const struct dpkg_arch 
*arch)
   }
 
   /* Need to create a new instance for the wanted architecture. */
-  pkg = nfmalloc(sizeof(struct pkginfo));
+  pkg = nfmalloc(sizeof(*pkg));
   pkg_blank(pkg);
   pkg->set = set;
   pkg->arch_next = NULL;
@@ -268,7 +268,7 @@ pkg_db_iter_new(void)
 {
   struct pkgiterator *iter;
 
-  iter = m_malloc(sizeof(struct pkgiterator));
+  iter = m_malloc(sizeof(*iter));
   iter->pkg = NULL;
   iter->nbinn = 0;
 
diff --git a/lib/dpkg/treewalk.c b/lib/dpkg/treewalk.c
index 3a669e6b0..dee072f2d 100644
--- a/lib/dpkg/treewalk.c
+++ b/lib/dpkg/treewalk.c
@@ -206,7 +206,7 @@ treenode_resize_down(struct treenode *node)
        else
                node->down_size = 8;
 
-       new_size = node->down_size * sizeof(struct treenode *);
+       new_size = node->down_size * sizeof(*node);
        node->down = m_realloc(node->down, new_size);
 }
 
@@ -367,7 +367,7 @@ treewalk_open(const char *rootdir, enum treewalk_options 
options,
        struct treeroot *tree;
        struct treenode *root;
 
-       tree = m_malloc(sizeof(struct treeroot));
+       tree = m_malloc(sizeof(*tree));
 
        tree->options = options;
        if (func)
diff --git a/src/archives.c b/src/archives.c
index a1013d73a..3df6424de 100644
--- a/src/archives.c
+++ b/src/archives.c
@@ -1188,7 +1188,7 @@ enqueue_deconfigure(struct pkginfo *pkg, struct pkginfo 
*pkg_removal)
 
   ensure_package_clientdata(pkg);
   pkg->clientdata->istobe = PKG_ISTOBE_DECONFIGURE;
-  newdeconf = m_malloc(sizeof(struct pkg_deconf_list));
+  newdeconf = m_malloc(sizeof(*newdeconf));
   newdeconf->next = deconfigure;
   newdeconf->pkg = pkg;
   newdeconf->pkg_removal = pkg_removal;
diff --git a/src/enquiry.c b/src/enquiry.c
index baf26daab..632322faa 100644
--- a/src/enquiry.c
+++ b/src/enquiry.c
@@ -292,7 +292,7 @@ unpackchk(const char *const *argv)
     if (!yettobeunpacked(pkg, &thissect)) continue;
     for (se= sectionentries; se && strcasecmp(thissect,se->name); se= 
se->next);
     if (!se) {
-      se= nfmalloc(sizeof(struct sectionentry));
+      se = nfmalloc(sizeof(*se));
       for (sep= &sectionentries;
            *sep && strcasecmp(thissect,(*sep)->name) > 0;
            sep= &(*sep)->next);
diff --git a/src/errors.c b/src/errors.c
index 6fa940856..5ecc101c3 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -59,7 +59,7 @@ enqueue_error_report(const char *arg)
 {
   struct error_report *nr;
 
-  nr= malloc(sizeof(struct error_report));
+  nr = malloc(sizeof(*nr));
   if (!nr) {
     notice(_("failed to allocate memory for new entry in list of failed 
packages: %s"),
            strerror(errno));
diff --git a/src/main.c b/src/main.c
index fc5804beb..b90e736c2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -448,7 +448,7 @@ set_invoke_hook(const struct cmdinfo *cip, const char 
*value)
   struct invoke_list *hook_list = cip->arg_ptr;
   struct invoke_hook *hook_new;
 
-  hook_new = m_malloc(sizeof(struct invoke_hook));
+  hook_new = m_malloc(sizeof(*hook_new));
   hook_new->command = m_strdup(value);
   hook_new->next = NULL;
 
diff --git a/src/perpkgstate.c b/src/perpkgstate.c
index 8a0667a68..75421122a 100644
--- a/src/perpkgstate.c
+++ b/src/perpkgstate.c
@@ -33,7 +33,7 @@ ensure_package_clientdata(struct pkginfo *pkg)
 {
        if (pkg->clientdata)
                return;
-       pkg->clientdata = nfmalloc(sizeof(struct perpackagestate));
+       pkg->clientdata = nfmalloc(sizeof(*pkg->clientdata));
        pkg->clientdata->istobe = PKG_ISTOBE_NORMAL;
        pkg->clientdata->color = PKG_CYCLE_WHITE;
        pkg->clientdata->enqueued = false;
diff --git a/src/remove.c b/src/remove.c
index 75f9c0f86..01d926387 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -206,7 +206,7 @@ void deferred_remove(struct pkginfo *pkg) {
 static void push_leftover(struct fileinlist **leftoverp,
                           struct filenamenode *namenode) {
   struct fileinlist *newentry;
-  newentry= nfmalloc(sizeof(struct fileinlist));
+  newentry = nfmalloc(sizeof(*newentry));
   newentry->next= *leftoverp;
   newentry->namenode= namenode;
   *leftoverp= newentry;
diff --git a/src/unpack.c b/src/unpack.c
index a42d0f7fa..3459b93c4 100644
--- a/src/unpack.c
+++ b/src/unpack.c
@@ -731,14 +731,14 @@ pkg_update_fields(struct pkginfo *pkg, struct 
filenamenode_queue *newconffiles)
   newdeplist = NULL;
   newdeplistlastp = &newdeplist;
   for (dep = pkg->available.depends; dep; dep = dep->next) {
-    newdep = nfmalloc(sizeof(struct dependency));
+    newdep = nfmalloc(sizeof(*newdep));
     newdep->up = pkg;
     newdep->next = NULL;
     newdep->list = NULL;
     newpossilastp = &newdep->list;
 
     for (possi = dep->list; possi; possi = possi->next) {
-      newpossi = nfmalloc(sizeof(struct deppossi));
+      newpossi = nfmalloc(sizeof(*newpossi));
       newpossi->up = newdep;
       newpossi->ed = possi->ed;
       newpossi->next = NULL;
@@ -783,7 +783,7 @@ pkg_update_fields(struct pkginfo *pkg, struct 
filenamenode_queue *newconffiles)
   pkg->installed.conffiles = NULL;
   iconffileslastp = &pkg->installed.conffiles;
   for (cfile = newconffiles->head; cfile; cfile = cfile->next) {
-    newiconff = nfmalloc(sizeof(struct conffile));
+    newiconff = nfmalloc(sizeof(*newiconff));
     newiconff->next = NULL;
     newiconff->name = nfstrsave(cfile->namenode->name);
     newiconff->hash = nfstrsave(cfile->namenode->oldhash);
@@ -1141,7 +1141,7 @@ void process_archive(const char *filename) {
   parsedb(cidir, parsedb_flags, &pkg);
 
   if (!pkg->archives) {
-    pkg->archives = nfmalloc(sizeof(struct archivedetails));
+    pkg->archives = nfmalloc(sizeof(*pkg->archives));
     pkg->archives->next = NULL;
     pkg->archives->name = NULL;
     pkg->archives->msdosname = NULL;

-- 
Dpkg.Org's dpkg

Reply via email to