public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [Bug general/23320] New: Incorrect usage of sizeof
@ 2018-06-20 17:13 serban at us dot ibm.com
  2018-06-20 20:12 ` [Bug general/23320] " mark at klomp dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: serban at us dot ibm.com @ 2018-06-20 17:13 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=23320

            Bug ID: 23320
           Summary: Incorrect usage of sizeof
           Product: elfutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: general
          Assignee: unassigned at sourceware dot org
          Reporter: serban at us dot ibm.com
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

The following diff show the incorrect usages of the sizeof routine:
--> git diff src/ar.c src/nm.c src/readelf.c
diff --git a/src/ar.c b/src/ar.c
index bfb324c..58c8b11 100644
--- a/src/ar.c
+++ b/src/ar.c
@@ -919,7 +919,7 @@ do_oper_delete (const char *arfname, char **argv, int argc,
                long int instance)
 {
   bool *found = alloca (sizeof (bool) * argc);
-  memset (found, '\0', sizeof (found));
+  memset (found, '\0', sizeof (bool) * argc);

   /* List of the files we keep.  */
   struct armem *to_copy = NULL;
diff --git a/src/nm.c b/src/nm.c
index f78861e..6c86298 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -752,7 +752,7 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char
*fullname,
       if (unlikely (name == NULL))
        {
          name = alloca (sizeof "[invalid sh_name 0x12345678]");
-         snprintf (name, sizeof name, "[invalid sh_name %#" PRIx32 "]",
+         snprintf (name, sizeof "[invalid sh_name 0x12345678]", "[invalid
sh_name %#" PRIx32 "]",
                    gelf_getshdr (scn, &shdr_mem)->sh_name);
        }
       scnnames[elf_ndxscn (scn)] = name;
diff --git a/src/readelf.c b/src/readelf.c
index 4032bd4..69b2abb 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4787,7 +4787,7 @@ register_info (Ebl *ebl, unsigned int regno, const
Ebl_Register_Location *loc,
                                 bits ?: &ignore, type ?: &ignore);
   if (n <= 0)
     {
-      snprintf (name, sizeof name, "reg%u", loc->regno);
+      snprintf (name, REGNAMESZ, "reg%u", loc->regno);
       if (bits != NULL)
        *bits = loc->bits;
       if (type != NULL)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-20 21:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-20 17:13 [Bug general/23320] New: Incorrect usage of sizeof serban at us dot ibm.com
2018-06-20 20:12 ` [Bug general/23320] " mark at klomp dot org
2018-06-20 21:12 ` serban at us dot ibm.com
2018-06-20 21:21 ` mark at klomp dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).