Come up with startswith function.
New function in system.h that returns true if a string has a given
prefix, false otherwise. Use it in place of strncmp.
Signed-off-by: Martin Liška <mliska@suse.cz>
diff --git a/backends/ChangeLog b/backends/ChangeLog
index eb15c81..ac0e318 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * aarch64_symbol.c (aarch64_data_marker_symbol): Use startswith.
+ * arm_symbol.c (arm_data_marker_symbol): Likewise.
+
2021-02-01 Érico Nogueira <ericonr@disroot.org>
* ppc_initreg.c: Also include <asm/ptrace.h>.
diff --git a/backends/aarch64_symbol.c b/backends/aarch64_symbol.c
index 464a569..15e0805 100644
--- a/backends/aarch64_symbol.c
+++ b/backends/aarch64_symbol.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <elf.h>
#include <stddef.h>
#include <string.h>
@@ -104,7 +106,7 @@
return (sym != NULL && sname != NULL
&& sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
&& GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
- && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0));
+ && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
}
const char *
diff --git a/backends/arm_symbol.c b/backends/arm_symbol.c
index c8e1d7f..a733cff 100644
--- a/backends/arm_symbol.c
+++ b/backends/arm_symbol.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <elf.h>
#include <stddef.h>
#include <string.h>
@@ -154,5 +156,5 @@
return (sym != NULL && sname != NULL
&& sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
&& GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
- && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0));
+ && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
}
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 97f598f..249385b 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,9 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * debuginfod-client.c (debuginfod_query_server): Use startswith.
+ (debuginfod_add_http_header): Likewise.
+ * debuginfod.cxx: Likewise.
+
2021-05-04 Alice Zhang <alizhang@redhat.com>
* debuginfod-client.c (cache_miss_default_s): New static time_t,
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 4fa047f..cb51c26 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1054,7 +1054,7 @@
&scheme);
if(ok3 == CURLE_OK && scheme)
{
- if (strncmp (scheme, "HTTP", 4) == 0)
+ if (startswith (scheme, "HTTP"))
if (resp_code == 200)
{
verified_handle = msg->easy_handle;
@@ -1318,7 +1318,7 @@
/* Track if User-Agent: is being set. If so, signal not to add the
default one. */
- if (strncmp (header, "User-Agent:", 11) == 0)
+ if (startswith (header, "User-Agent:"))
client->user_agent_set_p = 1;
client->headers = temp;
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 0e6fd13..e0948ea 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -37,6 +37,7 @@
#include "debuginfod.h"
#include <dwarf.h>
+#include <system.h>
#include <argp.h>
#ifdef __GNUC__
@@ -2323,15 +2324,15 @@
const char *section_name = elf_strptr (elf, shstrndx, shdr->sh_name);
if (section_name == NULL)
break;
- if (strncmp(section_name, ".debug_line", 11) == 0 ||
- strncmp(section_name, ".zdebug_line", 12) == 0)
+ if (startswith (section_name, ".debug_line") ||
+ startswith (section_name, ".zdebug_line"))
{
debuginfo_p = true;
dwarf_extract_source_paths (elf, debug_sourcefiles);
break; // expecting only one .*debug_line, so no need to look for others
}
- else if (strncmp(section_name, ".debug_", 7) == 0 ||
- strncmp(section_name, ".zdebug_", 8) == 0)
+ else if (startswith (section_name, ".debug_") ||
+ startswith (section_name, ".zdebug_"))
{
debuginfo_p = true;
// NB: don't break; need to parse .debug_line for sources
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 371e213..dd3ebca 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,10 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * system.h (startswith): New function.
+ (pwrite_retry): Cast to char *.
+ (write_retry): Likewise.
+ (pread_retry): Likewise.
+
2021-02-05 Mark Wielaard <mark@klomp.org>
* printversion.c (print_version): Update copyright year.
diff --git a/lib/system.h b/lib/system.h
index 1c478e1..cdf18ed 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -37,6 +37,7 @@
#include <endian.h>
#include <byteswap.h>
#include <unistd.h>
+#include <string.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define LE32(n) (n)
@@ -69,6 +70,14 @@
((void *) ((char *) memcpy (dest, src, n) + (size_t) n))
#endif
+/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+
/* A special gettext function we use if the strings are too short. */
#define sgettext(Str) \
({ const char *__res = strrchr (_(Str), '|'); \
@@ -104,7 +113,7 @@
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, buf + recvd, len - recvd,
+ ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len - recvd,
off + recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
@@ -123,7 +132,7 @@
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (write (fd, buf + recvd, len - recvd));
+ ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len - recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
@@ -141,7 +150,7 @@
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, buf + recvd, len - recvd,
+ ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len - recvd,
off + recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
diff --git a/libasm/ChangeLog b/libasm/ChangeLog
index 98ac331..85e723e 100644
--- a/libasm/ChangeLog
+++ b/libasm/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * libasmP.h (asm_emit_symbol_p): Use startswith.
+
2020-12-16 Dmitry V. Levin <ldv@altlinux.org>
* libasmP.h (_): Remove.
diff --git a/libasm/libasmP.h b/libasm/libasmP.h
index 8b72f32..5b5fb77 100644
--- a/libasm/libasmP.h
+++ b/libasm/libasmP.h
@@ -302,6 +302,6 @@
// XXX The second part should probably be controlled by an option which
// isn't implemented yet
// XXX Also, the format will change with the backend.
-#define asm_emit_symbol_p(name) (strncmp (name, ".L", 2) != 0)
+#define asm_emit_symbol_p(name) (!startswith (name, ".L"))
#endif /* libasmP.h */
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index aa3e5ee..b5462ef 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,7 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * dwarf_begin_elf.c (check_section): Use startswith.
+
2021-05-01 Mark Wielaard <mark@klomp.org>
* libdw_form.c (__libdw_form_val_compute_len): Check indirect
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 757ac4f..9e944b8 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
@@ -138,7 +140,7 @@
break;
}
else if (scnlen > 14 /* .gnu.debuglto_ prefix. */
- && strncmp (scnname, ".gnu.debuglto_", 14) == 0
+ && startswith (scnname, ".gnu.debuglto_")
&& strcmp (&scnname[14], dwarf_scnnames[cnt]) == 0)
break;
}
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d107e78..fedf65a 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,13 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * dwfl_frame.c (dwfl_attach_state): Use startswith.
+ * dwfl_module_getdwarf.c (find_symtab): Likewise.
+ * linux-kernel-modules.c: Likewise.
+ * linux-pid-attach.c (linux_proc_pid_is_stopped): Likewise.
+ (dwfl_linux_proc_attach): Likewise.
+ * relocate.c (resolve_symbol): Likewise.
+ (relocate_section): Likewise.
+
2021-02-01 Érico Nogueira <ericonr@disroot.org>
* dwfl_error.c (strerror_r): Only use the GNU version when available.
diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c
index 5bbf850..77e0c5c 100644
--- a/libdwfl/dwfl_frame.c
+++ b/libdwfl/dwfl_frame.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include "libdwflP.h"
#include <unistd.h>
@@ -172,7 +174,7 @@
is called from dwfl_linux_proc_attach with elf == NULL.
__libdwfl_module_getebl will call __libdwfl_getelf which
will call the find_elf callback. */
- if (strncmp (mod->name, "[vdso: ", 7) == 0
+ if (startswith (mod->name, "[vdso: ")
|| strcmp (strrchr (mod->name, ' ') ?: "",
" (deleted)") == 0)
continue;
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 2f3dd0d..6f07605 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -1162,7 +1162,7 @@
if (sname == NULL)
goto elferr;
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
/* Try to uncompress, but it might already have been, an error
might just indicate, already uncompressed. */
elf_compress_gnu (symstrscn, 0, 0);
@@ -1245,7 +1245,7 @@
if (sname == NULL)
goto elferr;
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
/* Try to uncompress, but it might already have been, an error
might just indicate, already uncompressed. */
elf_compress_gnu (aux_strscn, 0, 0);
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
index 6edb27f..c0f8dfa 100644
--- a/libdwfl/linux-kernel-modules.c
+++ b/libdwfl/linux-kernel-modules.c
@@ -924,7 +924,7 @@
if (!strcmp (secname, ".modinfo")
|| !strcmp (secname, ".data.percpu")
- || !strncmp (secname, ".exit", 5))
+ || startswith (secname, ".exit"))
{
*addr = (Dwarf_Addr) -1l;
return DWARF_CB_OK;
@@ -935,7 +935,7 @@
behavior, and this cruft leaks out into the /sys information.
The file name for ".init*" may actually look like "_init*". */
- const bool is_init = !strncmp (secname, ".init", 5);
+ const bool is_init = startswith (secname, ".init");
if (is_init)
{
if (asprintf (&sysfile, SECADDRDIRFMT "_%s",
diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c
index fdf5c9b..cd53482 100644
--- a/libdwfl/linux-pid-attach.c
+++ b/libdwfl/linux-pid-attach.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include "libelfP.h"
#include "libdwflP.h"
#include <sys/types.h>
@@ -59,7 +61,7 @@
have_state = false;
while (fgets (buffer, sizeof (buffer), procfile) != NULL)
- if (strncmp (buffer, "State:", 6) == 0)
+ if (startswith (buffer, "State:"))
{
have_state = true;
break;
@@ -407,7 +409,7 @@
char *line = NULL;
size_t linelen = 0;
while (getline (&line, &linelen, procfile) >= 0)
- if (strncmp (line, "Tgid:", 5) == 0)
+ if (startswith (line, "Tgid:"))
{
errno = 0;
char *endptr;
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c
index 88b5211..0497bd4 100644
--- a/libdwfl/relocate.c
+++ b/libdwfl/relocate.c
@@ -30,6 +30,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include "libelfP.h"
#include "libdwflP.h"
@@ -237,7 +239,7 @@
return DWFL_E_LIBELF;
/* If the section is already decompressed, that isn't an error. */
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
elf_compress_gnu (scn, 0, 0);
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -518,7 +520,7 @@
Nothing to do here. */
return DWFL_E_NOERROR;
- if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
+ if (startswith (tname, ".zdebug"))
elf_compress_gnu (tscn, 0, 0);
if ((tshdr->sh_flags & SHF_COMPRESSED) != 0)
@@ -539,7 +541,7 @@
if (sname == NULL)
return DWFL_E_LIBELF;
- if (strncmp (sname, ".zdebug", strlen ("zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
elf_compress_gnu (scn, 0, 0);
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 33208f0..fff66b3 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,8 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * eblobjnotetypename.c (ebl_object_note_type_name): Use startswith.
+ * eblopenbackend.c (default_debugscn_p): Likewise.
+
2020-12-16 Dmitry V. Levin <ldv@altlinux.org>
* libeblP.h (_): Remove.
diff --git a/libebl/eblobjnotetypename.c b/libebl/eblobjnotetypename.c
index 9daddcd..4662906 100644
--- a/libebl/eblobjnotetypename.c
+++ b/libebl/eblobjnotetypename.c
@@ -31,6 +31,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
@@ -79,8 +81,7 @@
}
}
- if (strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
- strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0)
+ if (startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX))
{
/* GNU Build Attribute notes (ab)use the owner name to store
most of their data. Don't decode everything here. Just
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index a8af165..71fafed 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -616,9 +616,9 @@
/ sizeof (dwarf_scn_names[0]));
for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt)
if (strcmp (name, dwarf_scn_names[cnt]) == 0
- || (strncmp (name, ".zdebug", strlen (".zdebug")) == 0
+ || (startswith (name, ".zdebug")
&& strcmp (&name[2], &dwarf_scn_names[cnt][1]) == 0)
- || (strncmp (name, ".gnu.debuglto_", strlen (".gnu.debuglto_")) == 0
+ || (startswith (name, ".gnu.debuglto_")
&& strcmp (&name[14], dwarf_scn_names[cnt]) == 0))
return true;
diff --git a/src/ChangeLog b/src/ChangeLog
index 0cea28e..c5ecc05 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * elfclassify.c (run_classify): Use startswith.
+ * elfcompress.c (process_file): Likewise.
+ * nm.c (show_symbols_sysv): Likewise.
+ * readelf.c (print_debug): Likewise.
+ (handle_notes_data): Likewise.
+ (dump_data_section): Likewise.
+ (print_string_section): Likewise.
+ * strip.c (remove_debug_relocations): Likewise.
+
2021-04-03 Mark Wielaard <mark@klomp.org>
* nm.c (show_symbols): close dwfl_fd if dwfl_begin fails.
diff --git a/src/elfclassify.c b/src/elfclassify.c
index ae626bb..fe7eeee 100644
--- a/src/elfclassify.c
+++ b/src/elfclassify.c
@@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
+#include <system.h>
#include <argp.h>
#include <error.h>
@@ -335,11 +336,8 @@
stderr);
has_bits_alloc = true;
}
- const char *debug_prefix = ".debug_";
- const char *zdebug_prefix = ".zdebug_";
- if (strncmp (section_name, debug_prefix, strlen (debug_prefix)) == 0
- || strncmp (section_name, zdebug_prefix,
- strlen (zdebug_prefix)) == 0)
+ if (startswith (section_name, ".debug_")
+ || startswith (section_name, ".zdebug_"))
{
if (verbose > 1 && !has_debug_sections)
fputs ("debug: .debug_* section found\n", stderr);
diff --git a/src/elfcompress.c b/src/elfcompress.c
index c5ba6c3..d5bc330 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -448,7 +448,7 @@
{
if (!force && type == T_DECOMPRESS
&& (shdr->sh_flags & SHF_COMPRESSED) == 0
- && strncmp (sname, ".zdebug", strlen (".zdebug")) != 0)
+ && !startswith (sname, ".zdebug"))
{
if (verbose > 0)
printf ("[%zd] %s already decompressed\n", ndx, sname);
@@ -460,7 +460,7 @@
printf ("[%zd] %s already compressed\n", ndx, sname);
}
else if (!force && type == T_COMPRESS_GNU
- && strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ && startswith (sname, ".zdebug"))
{
if (verbose > 0)
printf ("[%zd] %s already GNU compressed\n", ndx, sname);
@@ -472,11 +472,9 @@
/* Check if we might want to change this section name. */
if (! adjust_names
&& ((type != T_COMPRESS_GNU
- && strncmp (sname, ".zdebug",
- strlen (".zdebug")) == 0)
+ && startswith (sname, ".zdebug"))
|| (type == T_COMPRESS_GNU
- && strncmp (sname, ".debug",
- strlen (".debug")) == 0)))
+ && startswith (sname, ".debug"))))
adjust_names = true;
/* We need a buffer this large if we change the names. */
@@ -696,7 +694,7 @@
false, false, verbose > 0) < 0)
goto cleanup;
}
- else if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (sname, ".zdebug"))
{
snamebuf[0] = '.';
strcpy (&snamebuf[1], &sname[2]);
@@ -710,7 +708,7 @@
break;
case T_COMPRESS_GNU:
- if (strncmp (sname, ".debug", strlen (".debug")) == 0)
+ if (startswith (sname, ".debug"))
{
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
{
@@ -757,7 +755,7 @@
}
else if (verbose >= 0)
{
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
printf ("[%zd] %s unchanged, already GNU compressed",
ndx, sname);
else
@@ -769,7 +767,7 @@
case T_COMPRESS_ZLIB:
if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
{
- if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
{
/* First decompress to recompress zlib style.
Don't report even when verbose. */
@@ -900,7 +898,7 @@
symtab_size = size;
symtab_compressed = T_COMPRESS_ZLIB;
}
- else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (name, ".zdebug"))
{
/* Don't report the (internal) uncompression. */
if (compress_section (newscn, size, sname, NULL, ndx,
@@ -1046,7 +1044,7 @@
shstrtab_size = shdr->sh_size;
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
shstrtab_compressed = T_COMPRESS_ZLIB;
- else if (strncmp (shstrtab_name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (shstrtab_name, ".zdebug"))
shstrtab_compressed = T_COMPRESS_GNU;
}
@@ -1187,8 +1185,7 @@
symtab_size = shdr->sh_size;
if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
symtab_compressed = T_COMPRESS_ZLIB;
- else if (strncmp (symtab_name, ".zdebug",
- strlen (".zdebug")) == 0)
+ else if (startswith (symtab_name, ".zdebug"))
symtab_compressed = T_COMPRESS_GNU;
}
diff --git a/src/nm.c b/src/nm.c
index dc2186d..b99805e 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -858,7 +858,7 @@
bind = ebl_symbol_binding_name (ebl,
GELF_ST_BIND (syms[cnt].sym.st_info),
symbindbuf, sizeof (symbindbuf));
- if (bind != NULL && strncmp (bind, "GNU_", strlen ("GNU_")) == 0)
+ if (bind != NULL && startswith (bind, "GNU_"))
bind += strlen ("GNU_");
printf ("%-*s|%s|%-6s|%-8s|%s|%*s|%s\n",
longest_name, symstr, addressbuf, bind,
diff --git a/src/readelf.c b/src/readelf.c
index b974045..9b47262 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1335,7 +1335,7 @@
_("bad compression header for section %zd: %s"),
elf_ndxscn (scn), elf_errmsg (-1));
}
- else if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+ else if (startswith (sname, ".zdebug"))
{
ssize_t size;
if ((size = dwelf_scn_gnu_compressed_size (scn)) >= 0)
@@ -11451,7 +11451,7 @@
|| (scnlen == dbglen + 5
&& strstr (name, ".dwo") == name + dbglen + 1)))
|| (scnlen > 14 /* .gnu.debuglto_ prefix. */
- && strncmp (name, ".gnu.debuglto_", 14) == 0
+ && startswith (name, ".gnu.debuglto_")
&& strcmp (&name[14], debug_sections[n].name) == 0)
)
{
@@ -12455,8 +12455,7 @@
into the owner name field. Extract just the owner name
prefix here, then use the rest later as data. */
bool is_gnu_build_attr
- = strncmp (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX,
- strlen (ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX)) == 0;
+ = startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX);
const char *print_name = (is_gnu_build_attr
? ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX : name);
size_t print_namesz = (is_gnu_build_attr
@@ -12636,7 +12635,7 @@
_("Couldn't uncompress section"),
elf_ndxscn (scn));
}
- else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (name, ".zdebug"))
{
if (elf_compress_gnu (scn, 0, 0) < 0)
printf ("WARNING: %s [%zd]\n",
@@ -12687,7 +12686,7 @@
_("Couldn't uncompress section"),
elf_ndxscn (scn));
}
- else if (strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ else if (startswith (name, ".zdebug"))
{
if (elf_compress_gnu (scn, 0, 0) < 0)
printf ("WARNING: %s [%zd]\n",
diff --git a/src/strip.c b/src/strip.c
index 7a5d4e4..70fc8c0 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -607,7 +607,7 @@
GElf_Chdr tchdr;
int tcompress_type = 0;
bool is_gnu_compressed = false;
- if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0)
+ if (startswith (tname, ".zdebug"))
{
is_gnu_compressed = true;
if (elf_compress_gnu (tscn, 0, 0) != 1)
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 35fb2b2..4951e14 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,11 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * dwelf_elf_e_machine_string.c (main): Use startswith.
+ * dwelfgnucompressed.c (main): Likewise.
+ * elfgetchdr.c (main): Likewise.
+ * elfputzdata.c (main): Likewise.
+ * vdsosyms.c (module_callback): Likewise.
+
2021-05-04 Alice Zhang <alizhang@redhat.com>
* run-debuginfod-find.sh: Added tests for negative cache files.
diff --git a/tests/dwelf_elf_e_machine_string.c b/tests/dwelf_elf_e_machine_string.c
index afad105..30599c3 100644
--- a/tests/dwelf_elf_e_machine_string.c
+++ b/tests/dwelf_elf_e_machine_string.c
@@ -19,6 +19,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
@@ -41,7 +43,7 @@
const char *machine;
errno = 0;
- if (strncmp ("0x", argv[i], 2) == 0)
+ if (startswith (argv[i], "0x"))
val = strtol (&argv[i][2], NULL, 16);
else
val = strtol (argv[i], NULL, 10);
diff --git a/tests/dwelfgnucompressed.c b/tests/dwelfgnucompressed.c
index 0132271..447f3d5 100644
--- a/tests/dwelfgnucompressed.c
+++ b/tests/dwelfgnucompressed.c
@@ -18,6 +18,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -82,7 +84,7 @@
break;
}
- if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
{
ssize_t size;
if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1)
diff --git a/tests/elfgetchdr.c b/tests/elfgetchdr.c
index 44ba178..171c4df 100644
--- a/tests/elfgetchdr.c
+++ b/tests/elfgetchdr.c
@@ -18,6 +18,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -99,7 +101,7 @@
}
/* This duplicates what the dwelfgnucompressed testcase does. */
- if (strncmp(".zdebug", sname, strlen (".zdebug")) == 0)
+ if (startswith (sname, ".zdebug"))
{
ssize_t size;
if ((size = dwelf_scn_gnu_compressed_size (scn)) == -1)
diff --git a/tests/elfputzdata.c b/tests/elfputzdata.c
index 0d9c020..0ff363f 100644
--- a/tests/elfputzdata.c
+++ b/tests/elfputzdata.c
@@ -18,6 +18,8 @@
# include <config.h>
#endif
+#include <system.h>
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -83,7 +85,7 @@
printf ("Cannot compress %zd %s\n", idx, name);
}
else if ((shdr->sh_flags & SHF_COMPRESSED) != 0
- || strncmp (name, ".zdebug", strlen (".zdebug")) == 0)
+ || startswith (name, ".zdebug"))
{
printf ("Already compressed %zd %s\n", idx, name);
}
diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c
index 83ab034..ff1a18a 100644
--- a/tests/vdsosyms.c
+++ b/tests/vdsosyms.c
@@ -43,7 +43,7 @@
{
/* We can only recognize the vdso by inspecting the "magic name". */
printf ("module name: %s\n", name);
- if (strncmp ("[vdso: ", name, 7) == 0)
+ if (startswith (name, "[vdso: "))
{
vdso_syms = dwfl_module_getsymtab (mod);
printf ("vdso syms: %d\n", vdso_syms);