public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] abg-reader: eliminate unreachable-code-loop-increment warnings
@ 2021-06-16 13:30 Giuliano Procida
  2021-06-16 13:35 ` Matthias Maennich
  0 siblings, 1 reply; 2+ messages in thread
From: Giuliano Procida @ 2021-06-16 13:30 UTC (permalink / raw)
  To: libabigail; +Cc: dodji, kernel-team, gprocida, maennich

This commit tidies up some debris from the change to use
xmlFirstElementChild and xmlNextElementSibling. A couple of while
loops had bodies which would be executed exactly once searching for
the next element with a given tag. These trigger warnings with recent
Clang++, at least.

This commit replaces the loops with their bodies and eliminates
a little redundant conditional logic.

There is no change in behaviour.

	* src/abg-reader.cc (read_translation_unit_from_input): In the
	branch where the context object holds a non-null node, just
	check that it an abi-instr; remove the final null check on
	node as it is guaranteed to be non-null.
	(read_elf_needed_from_input): Save the context object's node
	in node immediately; in the branch where the context object
	holds a non-null node, just check that it an elf-needed;
	remove the final null check on node as it is guaranteed to be
	non-null.

Signed-off-by: Giuliano Procida <gprocida@google.com>
---
 src/abg-reader.cc | 41 +++++++++--------------------------------
 1 file changed, 9 insertions(+), 32 deletions(-)

diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index 0b8149f6..793ca828 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -1576,21 +1576,10 @@ read_translation_unit_from_input(read_context&	ctxt)
     }
   else
     {
-      node = 0;
-      for (xmlNodePtr n = ctxt.get_corpus_node();
-	   n;
-	   n = xmlNextElementSibling(n))
-	{
-	  if (!xmlStrEqual(n->name, BAD_CAST("abi-instr")))
-	    return nil;
-	  node = n;
-	  break;
-	}
+      if (!xmlStrEqual(node->name, BAD_CAST("abi-instr")))
+	return nil;
     }
 
-  if (node == 0)
-    return nil;
-
   tu = get_or_read_and_add_translation_unit(ctxt, node);
 
   if (ctxt.get_corpus_node())
@@ -1740,9 +1729,8 @@ read_elf_needed_from_input(read_context&	ctxt,
   if (!reader)
     return false;
 
-  xmlNodePtr node = 0;
-
-  if (ctxt.get_corpus_node() == 0)
+  xmlNodePtr node = ctxt.get_corpus_node();
+  if (!node)
     {
       int status = 1;
       while (status == 1
@@ -1762,24 +1750,13 @@ read_elf_needed_from_input(read_context&	ctxt,
     }
   else
     {
-      for (xmlNodePtr n = ctxt.get_corpus_node();
-	   n;
-	   n = xmlNextElementSibling(n))
-	{
-	  if (!xmlStrEqual(n->name, BAD_CAST("elf-needed")))
-	    return false;
-	  node = n;
-	  break;
-	}
+      if (!xmlStrEqual(node->name, BAD_CAST("elf-needed")))
+        return false;
     }
 
-  bool result = false;
-  if (node)
-    {
-      result = build_needed(node, needed);
-      node = xmlNextElementSibling(node);
-      ctxt.set_corpus_node(node);
-    }
+  bool result = build_needed(node, needed);
+  node = xmlNextElementSibling(node);
+  ctxt.set_corpus_node(node);
 
   return result;
 }
-- 
2.32.0.272.g935e593368-goog


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

* Re: [PATCH] abg-reader: eliminate unreachable-code-loop-increment warnings
  2021-06-16 13:30 [PATCH] abg-reader: eliminate unreachable-code-loop-increment warnings Giuliano Procida
@ 2021-06-16 13:35 ` Matthias Maennich
  0 siblings, 0 replies; 2+ messages in thread
From: Matthias Maennich @ 2021-06-16 13:35 UTC (permalink / raw)
  To: Giuliano Procida; +Cc: libabigail, dodji, kernel-team

On Wed, Jun 16, 2021 at 02:30:03PM +0100, Giuliano Procida wrote:
>This commit tidies up some debris from the change to use
>xmlFirstElementChild and xmlNextElementSibling. A couple of while
>loops had bodies which would be executed exactly once searching for
>the next element with a given tag. These trigger warnings with recent
>Clang++, at least.
>
>This commit replaces the loops with their bodies and eliminates
>a little redundant conditional logic.
>
>There is no change in behaviour.
>
>	* src/abg-reader.cc (read_translation_unit_from_input): In the
>	branch where the context object holds a non-null node, just
>	check that it an abi-instr; remove the final null check on
>	node as it is guaranteed to be non-null.
>	(read_elf_needed_from_input): Save the context object's node
>	in node immediately; in the branch where the context object
>	holds a non-null node, just check that it an elf-needed;
>	remove the final null check on node as it is guaranteed to be
>	non-null.
>
>Signed-off-by: Giuliano Procida <gprocida@google.com>

Reviewed-by: Matthias Maennich <maennich@google.com>

Cheers,
Matthias

>---
> src/abg-reader.cc | 41 +++++++++--------------------------------
> 1 file changed, 9 insertions(+), 32 deletions(-)
>
>diff --git a/src/abg-reader.cc b/src/abg-reader.cc
>index 0b8149f6..793ca828 100644
>--- a/src/abg-reader.cc
>+++ b/src/abg-reader.cc
>@@ -1576,21 +1576,10 @@ read_translation_unit_from_input(read_context&	ctxt)
>     }
>   else
>     {
>-      node = 0;
>-      for (xmlNodePtr n = ctxt.get_corpus_node();
>-	   n;
>-	   n = xmlNextElementSibling(n))
>-	{
>-	  if (!xmlStrEqual(n->name, BAD_CAST("abi-instr")))
>-	    return nil;
>-	  node = n;
>-	  break;
>-	}
>+      if (!xmlStrEqual(node->name, BAD_CAST("abi-instr")))
>+	return nil;
>     }
>
>-  if (node == 0)
>-    return nil;
>-
>   tu = get_or_read_and_add_translation_unit(ctxt, node);
>
>   if (ctxt.get_corpus_node())
>@@ -1740,9 +1729,8 @@ read_elf_needed_from_input(read_context&	ctxt,
>   if (!reader)
>     return false;
>
>-  xmlNodePtr node = 0;
>-
>-  if (ctxt.get_corpus_node() == 0)
>+  xmlNodePtr node = ctxt.get_corpus_node();
>+  if (!node)
>     {
>       int status = 1;
>       while (status == 1
>@@ -1762,24 +1750,13 @@ read_elf_needed_from_input(read_context&	ctxt,
>     }
>   else
>     {
>-      for (xmlNodePtr n = ctxt.get_corpus_node();
>-	   n;
>-	   n = xmlNextElementSibling(n))
>-	{
>-	  if (!xmlStrEqual(n->name, BAD_CAST("elf-needed")))
>-	    return false;
>-	  node = n;
>-	  break;
>-	}
>+      if (!xmlStrEqual(node->name, BAD_CAST("elf-needed")))
>+        return false;
>     }
>
>-  bool result = false;
>-  if (node)
>-    {
>-      result = build_needed(node, needed);
>-      node = xmlNextElementSibling(node);
>-      ctxt.set_corpus_node(node);
>-    }
>+  bool result = build_needed(node, needed);
>+  node = xmlNextElementSibling(node);
>+  ctxt.set_corpus_node(node);
>
>   return result;
> }
>-- 
>2.32.0.272.g935e593368-goog
>

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

end of thread, other threads:[~2021-06-16 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 13:30 [PATCH] abg-reader: eliminate unreachable-code-loop-increment warnings Giuliano Procida
2021-06-16 13:35 ` Matthias Maennich

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