* [RFC] Fix compiler warnings in osabi.c
@ 2006-01-10 22:22 Mark Kettenis
2006-01-11 4:19 ` Daniel Jacobowitz
2006-01-11 4:22 ` Eli Zaretskii
0 siblings, 2 replies; 6+ messages in thread
From: Mark Kettenis @ 2006-01-10 22:22 UTC (permalink / raw)
To: gdb-patches
Another GCC 4 warning; e_ident[] is an array of unsigned chars. I
think the most elegant way to solve this is to use memcmp instead of
strcmp, since we're comparing a string to what may be random garbage,
and not two strings.
This one isn't quite so obvious, but if nobody objects, I'll commit
this after a week.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* osabi.c (generic_elf_osabi_sniffer): Use memcmp instead of
strcmp to compare string to an arbitrary 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 10 Jan 2006 22:18:43 -0000
@@ -546,7 +546,7 @@ 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", 8) == 0)
osabi = GDB_OSABI_FREEBSD_ELF;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] Fix compiler warnings in osabi.c
2006-01-10 22:22 [RFC] Fix compiler warnings in osabi.c Mark Kettenis
@ 2006-01-11 4:19 ` Daniel Jacobowitz
2006-01-11 4:22 ` Eli Zaretskii
1 sibling, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2006-01-11 4:19 UTC (permalink / raw)
To: Mark Kettenis; +Cc: gdb-patches
On Tue, Jan 10, 2006 at 11:22:23PM +0100, Mark Kettenis wrote:
> Another GCC 4 warning; e_ident[] is an array of unsigned chars. I
> think the most elegant way to solve this is to use memcmp instead of
> strcmp, since we're comparing a string to what may be random garbage,
> and not two strings.
>
> This one isn't quite so obvious, but if nobody objects, I'll commit
> this after a week.
Yes, looks right to me.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] Fix compiler warnings in osabi.c
2006-01-10 22:22 [RFC] Fix compiler warnings in osabi.c Mark Kettenis
2006-01-11 4:19 ` Daniel Jacobowitz
@ 2006-01-11 4:22 ` Eli Zaretskii
2006-01-15 20:23 ` Mark Kettenis
1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2006-01-11 4:22 UTC (permalink / raw)
To: Mark Kettenis; +Cc: gdb-patches
> 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.
WDYT?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] Fix compiler warnings in osabi.c
2006-01-11 4:22 ` Eli Zaretskii
@ 2006-01-15 20:23 ` Mark Kettenis
2006-01-15 21:38 ` Eli Zaretskii
0 siblings, 1 reply; 6+ messages in thread
From: Mark Kettenis @ 2006-01-15 20:23 UTC (permalink / raw)
To: eliz; +Cc: gdb-patches
> 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;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] Fix compiler warnings in osabi.c
2006-01-15 20:23 ` Mark Kettenis
@ 2006-01-15 21:38 ` Eli Zaretskii
2006-01-15 22:28 ` Mark Kettenis
0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2006-01-15 21:38 UTC (permalink / raw)
To: Mark Kettenis; +Cc: gdb-patches
> Date: Sun, 15 Jan 2006 21:23:40 +0100 (CET)
> From: Mark Kettenis <mark.kettenis@xs4all.nl>
> CC: gdb-patches@sourceware.org
>
> 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.
The compiler will probably optimize, allright, but we now have the
same string in two places in the sources, which creates a window,
albeit a small one, for discrepancies.
> 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;
> }
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] Fix compiler warnings in osabi.c
2006-01-15 21:38 ` Eli Zaretskii
@ 2006-01-15 22:28 ` Mark Kettenis
0 siblings, 0 replies; 6+ messages in thread
From: Mark Kettenis @ 2006-01-15 22:28 UTC (permalink / raw)
To: eliz; +Cc: gdb-patches
> Date: Sun, 15 Jan 2006 23:38:12 +0200
> From: Eli Zaretskii <eliz@gnu.org>
>
> > Date: Sun, 15 Jan 2006 21:23:40 +0100 (CET)
> > From: Mark Kettenis <mark.kettenis@xs4all.nl>
> > CC: gdb-patches@sourceware.org
> >
> > 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.
>
> The compiler will probably optimize, allright, but we now have the
> same string in two places in the sources, which creates a window,
> albeit a small one, for discrepancies.
Well, I think that's acceptable. This string is not going to change,
and both strings are right next to eachother.
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-01-15 22:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-10 22:22 [RFC] Fix compiler warnings in osabi.c Mark Kettenis
2006-01-11 4:19 ` Daniel Jacobowitz
2006-01-11 4:22 ` Eli Zaretskii
2006-01-15 20:23 ` Mark Kettenis
2006-01-15 21:38 ` Eli Zaretskii
2006-01-15 22:28 ` Mark Kettenis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox