This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC] Fix compiler warnings in osabi.c
> Date: Wed, 11 Jan 2006 06:22:09 +0200
> From: Eli Zaretskii <eliz@gnu.org>
>
> > Date: Tue, 10 Jan 2006 23:22:23 +0100 (CET)
> > From: Mark Kettenis <mark.kettenis@xs4all.nl>
> >
> > - if (strcmp (&elf_elfheader (abfd)->e_ident[8], "FreeBSD") == 0)
> > + if (memcmp (&elf_elfheader (abfd)->e_ident[8], "FreeBSD", 8) == 0)
>
> I'm allergic to magic constants such as 8. Can we please make that
> use sizeof("FreeBSD")? To avoid having two instances of "FreeBSD" in
> the code, you could use a `const char []' variable with "FreeBSD" as
> its value.
It's a reasonable request, although I'd prefer to keep the literal as
is. The compiler should optimize away sizeof("FreeBSD") anyway. So I
committed the attached.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* osabi.c (generic_elf_osabi_sniffer): Use memcmp instead of
strcmp to compare string to a byte buffer.
Index: osabi.c
===================================================================
RCS file: /cvs/src/src/gdb/osabi.c,v
retrieving revision 1.34
diff -u -p -r1.34 osabi.c
--- osabi.c 17 Dec 2005 22:34:01 -0000 1.34
+++ osabi.c 15 Jan 2006 20:19:28 -0000
@@ -546,7 +546,8 @@ generic_elf_osabi_sniffer (bfd *abfd)
/* The FreeBSD folks have been naughty; they stored the string
"FreeBSD" in the padding of the e_ident field of the ELF
header to "brand" their ELF binaries in FreeBSD 3.x. */
- if (strcmp (&elf_elfheader (abfd)->e_ident[8], "FreeBSD") == 0)
+ if (memcmp (&elf_elfheader (abfd)->e_ident[8],
+ "FreeBSD", sizeof ("FreeBSD") == 0)
osabi = GDB_OSABI_FREEBSD_ELF;
}