src/elflint.c: fix printing of unknown flags
authorSergei Trofimovich <slyfox@gentoo.org>
Thu, 31 Dec 2020 12:11:42 +0000 (12:11 +0000)
committerMark Wielaard <mark@klomp.org>
Mon, 11 Jan 2021 22:31:44 +0000 (23:31 +0100)
before the change section_flags_string() ignored unknown section
flags: snprintf() did write numeric value into buffer, but
"*cp = '\0'" negated the effect.

The change advances the 'cp' pointer'.

While at it add a '|' separator between known and unknown flags.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
src/ChangeLog
src/elflint.c

index 5d0e384..a2f9603 100644 (file)
@@ -1,3 +1,8 @@
+2020-12-31  Sergei Trofimovich  <slyfox@gentoo.org>
+
+       * elflint.c (section_flags_string): Update cp pointer after
+       snprintf for unknown flags.
+
 2020-12-16  Érico Nogueira  <ericonr@disroot.org>
 
        * readelf.c (qsort_r): Use qsort for improved portability.
index b3cbaad..21cfa28 100644 (file)
@@ -2813,8 +2813,12 @@ section_flags_string (GElf_Word flags, char *buf, size_t len)
       }
 
   if (flags != 0 || cp == buf)
-    snprintf (cp, len - 1, "%" PRIx64, (uint64_t) flags);
-
+    {
+      int r = snprintf (cp, len - 1, "%s%" PRIx64,
+                       (cp == buf) ? "" : "|", (uint64_t) flags);
+      if (r > 0)
+       cp += r;
+    }
   *cp = '\0';
 
   return buf;