* [commit] Fix -Wunused warning in dec-thread.c.
@ 2010-01-12 7:56 Joel Brobecker
2010-01-12 12:23 ` Pedro Alves
0 siblings, 1 reply; 2+ messages in thread
From: Joel Brobecker @ 2010-01-12 7:56 UTC (permalink / raw)
To: gdb-patches
From: brobecke <brobecke@f8352e7e-cb20-0410-8ce7-b5d9e71c585c>
Hello,
The compiler complains that the result of a couple of *PTR++ is never
used. This is because the compiler is tricked by the way the pointer
was defined. For instance:
| dec_thread_count_gdb_threads (struct thread_info *ignored, void *context)
| {
| int *count = (int *) context;
The compiler complains that the result is never used for the following
line:
| *count++;
The result is stored for the caller to use, so it is in fact potentially
used, but elsewhere...
gdb/ChangeLog:
* dec-thread.c (dec_thread_count_gdb_threads)
(dec_thread_add_gdb_thread): Prevent -Wunused warning.
Checked in.
---
gdb/dec-thread.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gdb/dec-thread.c b/gdb/dec-thread.c
index 5083221..be6db4c 100644
--- a/gdb/dec-thread.c
+++ b/gdb/dec-thread.c
@@ -352,7 +352,7 @@ dec_thread_count_gdb_threads (struct thread_info *ignored, void *context)
{
int *count = (int *) context;
- *count++;
+ (void) *count++; /* The cast to void is to prevent a -Wunused warning. */
return 0;
}
@@ -366,7 +366,7 @@ dec_thread_add_gdb_thread (struct thread_info *info, void *context)
struct thread_info ***listp = (struct thread_info ***) context;
**listp = info;
- *listp++;
+ (void) *listp++; /* The cast to void is to prevent a -Wunused warning. */
return 0;
}
--
1.6.3.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [commit] Fix -Wunused warning in dec-thread.c.
2010-01-12 7:56 [commit] Fix -Wunused warning in dec-thread.c Joel Brobecker
@ 2010-01-12 12:23 ` Pedro Alves
0 siblings, 0 replies; 2+ messages in thread
From: Pedro Alves @ 2010-01-12 12:23 UTC (permalink / raw)
To: gdb-patches; +Cc: Joel Brobecker
On Tuesday 12 January 2010 07:56:11, Joel Brobecker wrote:
> From: brobecke <brobecke@f8352e7e-cb20-0410-8ce7-b5d9e71c585c>
>
> Hello,
>
> The compiler complains that the result of a couple of *PTR++ is never
> used. This is because the compiler is tricked by the way the pointer
> was defined. For instance:
>
> | dec_thread_count_gdb_threads (struct thread_info *ignored, void *context)
> | {
> | int *count = (int *) context;
>
> The compiler complains that the result is never used for the following
> line:
>
> | *count++;
>
> The result is stored for the caller to use, so it is in fact potentially
> used, but elsewhere...
>
> gdb/ChangeLog:
>
> * dec-thread.c (dec_thread_count_gdb_threads)
> (dec_thread_add_gdb_thread): Prevent -Wunused warning.
>
> Checked in.
>
> ---
> gdb/dec-thread.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/dec-thread.c b/gdb/dec-thread.c
> index 5083221..be6db4c 100644
> --- a/gdb/dec-thread.c
> +++ b/gdb/dec-thread.c
> @@ -352,7 +352,7 @@ dec_thread_count_gdb_threads (struct thread_info *ignored, void *context)
> {
> int *count = (int *) context;
>
> - *count++;
> + (void) *count++; /* The cast to void is to prevent a -Wunused warning. */
> return 0;
> }
>
Does the resulting gdb actually count threads correctly?
'++' has higher precedence than '*', so '*count++'
is incrementing the count pointer, not what it points to.
The correct fix is either:
- *count++;
+ (*count)++;
or
- *count++;
+ ++*count;
Grepping for `grep iterate_over * | grep count' shows that the
`(*count)++' form is used at least in two places, giter_count
and count_events_callback:
aix-thread.c:/* iterate_over_threads() callback for counting GDB threads.
aix-thread.c: iterate_over_threads (giter_count, &gcount);
dec-thread.c: iterate_over_threads (dec_thread_count_gdb_threads,
linux-nat.c: iterate_over_lwps (filter, count_events_callback, &num_events);
--
Pedro Alves
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-01-12 12:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-12 7:56 [commit] Fix -Wunused warning in dec-thread.c Joel Brobecker
2010-01-12 12:23 ` Pedro Alves
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox