public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* nlmconv.c - warning: value computed is not used
@ 2010-12-07 23:04 Bernd Jendrissek
  2010-12-08  5:22 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Bernd Jendrissek @ 2010-12-07 23:04 UTC (permalink / raw)
  To: binutils

In message <477B8342.60604@redhat.com> Nick Clifton wrote:
>> .././binutils/nlmconv.c: In function 'main':
>> .././binutils/nlmconv.c:1081: warning: value computed is not used
>>
>> but is it safe to ignore this warning?
>
>Possibly, but it is hard to be sure without being able to reproduce the bug.
>(I tried with my local sources, but I did not see this warning).  What does
>line 1081 in nlmconv.c in your sources look like ?  Is it this:
>
>   strncpy (nlm_variable_header (outbfd)->oldThreadName, " LONG",
>	   NLM_OLD_THREAD_NAME_LENGTH);
>
>[snip other alternative]

This is it in my case.

I'm using GCC 4.3.1, compiling binutils from a git mirror [*], and
trying random things to make the warning go away (I'm not really
interested in nlmconv itself, so I just #if 0'ed the call out), I
found that replacing NLM_OLD_THREAD_NAME_LENGTH with 7 or more
placated GCC; 6 and below (including the #definition or 5) provoked
the warning.  It's as if GCC insists that you write a buffer overflow
bug!  If GCC was somehow omniscient enough to reason that " LONG"
never gets used, fine, but I don't see how this can be the case, as
just a few lines later outbfd "escapes" out of main() into
abfd_close().

I'd be happy to follow suggestions on how to investigate this,
although trying later versions of GCC means getting quite a few ducks
in a row.

[*] commit message of the revision I was building says:

commit 93cf20549fb5a4cd15cdf0e2a5d68b2f415eeceb
Author: Nick Clifton <nickc@redhat.com>
Date:   Fri Jul 16 14:52:14 2010 +0000

            * corefile.c (core_sym_class): Fix handling of subprogram names
            and add support for cloned function names.

(I fetched some more git bits but the code in the vicinity of the
strncpy doesn't seem to have changed since July 16.)

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

* Re: nlmconv.c - warning: value computed is not used
  2010-12-07 23:04 nlmconv.c - warning: value computed is not used Bernd Jendrissek
@ 2010-12-08  5:22 ` Alan Modra
  2010-12-10 14:18   ` Bernd Jendrissek
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2010-12-08  5:22 UTC (permalink / raw)
  To: Bernd Jendrissek; +Cc: binutils

On Wed, Dec 08, 2010 at 01:03:55AM +0200, Bernd Jendrissek wrote:
> In message <477B8342.60604@redhat.com> Nick Clifton wrote:
> >> .././binutils/nlmconv.c: In function 'main':
> >> .././binutils/nlmconv.c:1081: warning: value computed is not used
> >>
> >> but is it safe to ignore this warning?
> >
> >Possibly, but it is hard to be sure without being able to reproduce the bug.
> >(I tried with my local sources, but I did not see this warning).  What does
> >line 1081 in nlmconv.c in your sources look like ?  Is it this:
> >
> >   strncpy (nlm_variable_header (outbfd)->oldThreadName, " LONG",
> >	   NLM_OLD_THREAD_NAME_LENGTH);
> >
> >[snip other alternative]
> 
> This is it in my case.

I wonder do you have a fancy macro for strncpy on your system?  What
does the preprocessor output look like here?

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: nlmconv.c - warning: value computed is not used
  2010-12-08  5:22 ` Alan Modra
@ 2010-12-10 14:18   ` Bernd Jendrissek
  0 siblings, 0 replies; 3+ messages in thread
From: Bernd Jendrissek @ 2010-12-10 14:18 UTC (permalink / raw)
  To: binutils

On Wed, Dec 8, 2010 at 7:22 AM, Alan Modra <amodra@gmail.com> wrote:
> On Wed, Dec 08, 2010 at 01:03:55AM +0200, Bernd Jendrissek wrote:
>> In message <477B8342.60604@redhat.com> Nick Clifton wrote:
>> >   strncpy (nlm_variable_header (outbfd)->oldThreadName, " LONG",
>> >        NLM_OLD_THREAD_NAME_LENGTH);
>> >
>> >[snip other alternative]
>>
>> This is it in my case.
>
> I wonder do you have a fancy macro for strncpy on your system?  What
> does the preprocessor output look like here?

Bingo.  This is what GCC (4.3.1 with an early-2000s glibc) sees on my system:

  (__extension__ (__builtin_constant_p (" LONG") &&
__builtin_constant_p (5) ? (strlen (" LONG") + 1 >= ((size_t) (5)) ?
(char *) memcpy ((((outbfd) -> tdata.nlm_obj_data) ->
nlm_variable_hdr)->oldThreadName, " LONG", 5) : strncpy ((((outbfd) ->
tdata.nlm_obj_data) -> nlm_variable_hdr)->oldThreadName, " LONG", 5))
: strncpy ((((outbfd) -> tdata.nlm_obj_data) ->
nlm_variable_hdr)->oldThreadName, " LONG", 5)));

Casting the call to strncpy to (void) makes the warning go away.  I'm
sure this is a non-issue on more recent systems.  Thanks for the hint.

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

end of thread, other threads:[~2010-12-10 14:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-07 23:04 nlmconv.c - warning: value computed is not used Bernd Jendrissek
2010-12-08  5:22 ` Alan Modra
2010-12-10 14:18   ` Bernd Jendrissek

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).