libctf: Remove unused variable initialized to itself

Message ID 20211006171807.26745-1-mforney@mforney.org
State New
Headers show
Series
  • libctf: Remove unused variable initialized to itself
Related show

Commit Message

Michael Forney Oct. 6, 2021, 5:18 p.m.
2021-10-06  Michael Forney  <mforney@mforney.org>

	* ctf-link.c: Remove unused variable initialized to itself.
---
 libctf/ctf-link.c | 1 -
 1 file changed, 1 deletion(-)

-- 
2.32.0

Comments

H.J. Lu via Binutils Oct. 8, 2021, 2:49 p.m. | #1
On 6 Oct 2021, Michael Forney spake thusly:

> 2021-10-06  Michael Forney  <mforney@mforney.org>

>

> 	* ctf-link.c: Remove unused variable initialized to itself.


Oops! Why didn't that elicit a compiler warning, I wonder...

>  libctf/ctf-link.c | 1 -

>  1 file changed, 1 deletion(-)

>

> diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c

> index cc99f818970..ebb2cffd398 100644

> --- a/libctf/ctf-link.c

> +++ b/libctf/ctf-link.c

> @@ -1594,7 +1594,6 @@ ctf_link_shuffle_syms (ctf_dict_t *fp)

>  

>    while ((err = ctf_dynhash_next (fp->ctf_dynsyms, &i, &name_, &sym_)) == 0)

>      {

> -      const char *name = (const char *) name;

>        ctf_link_sym_t *symp = (ctf_link_sym_t *) sym_;

>  

>        if (!ctf_assert (fp, symp->st_symidx <= fp->ctf_dynsymmax))


That'll work, but you can improve thins a bit more by dropping the name_
variable as well, and turning the &name_ parameter to ctf_dynhash_next
into a NULL, which is idiomatic for "I'm not using that" in _next()
functions.

(Clearly I thought I was going to use the symbol name at one point when
I wrote this code, then ended up not using it, so didn't notice the
typo: that line was meant to read

  const char *name = (const char *) name_;

to get the name into a variable of the right type; but since it's unused
that's useless.)

-- 
NULL && (void)

Patch

diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
index cc99f818970..ebb2cffd398 100644
--- a/libctf/ctf-link.c
+++ b/libctf/ctf-link.c
@@ -1594,7 +1594,6 @@  ctf_link_shuffle_syms (ctf_dict_t *fp)
 
   while ((err = ctf_dynhash_next (fp->ctf_dynsyms, &i, &name_, &sym_)) == 0)
     {
-      const char *name = (const char *) name;
       ctf_link_sym_t *symp = (ctf_link_sym_t *) sym_;
 
       if (!ctf_assert (fp, symp->st_symidx <= fp->ctf_dynsymmax))