Am 05.09.22 um 13:00 schrieb Paolo Bonzini:
test-visitor-serialization list tests is using an "if" to pick either the first
element of the list or the next one.  This was done presumably to mimic the
code that creates the list, which has to fill in either the head pointer
or the next pointer of the last element.  However, the code in the insert
phase is a pretty standard singly-linked list insertion, while the one
in the visit phase looks weird and even looks at the first item twice:
this is confusing because the test puts in 32 items and finishes with
an assertion that i == 33.

So, move the "else" step in a separate switch statement, and change
the do...while loop to a while, because cur_head has already been
initialized beforehand.

Signed-off-by: Paolo Bonzini <[email protected]>
---
  tests/unit/test-visitor-serialization.c | 157 +++++++++++-------------
  1 file changed, 69 insertions(+), 88 deletions(-)

diff --git a/tests/unit/test-visitor-serialization.c 
b/tests/unit/test-visitor-serialization.c
index 907263d030..667e8fed82 100644
--- a/tests/unit/test-visitor-serialization.c
+++ b/tests/unit/test-visitor-serialization.c
@@ -427,131 +427,117 @@ static void test_primitive_lists(gconstpointer opaque)
      ops->deserialize((void **)&pl_copy_ptr, serialize_data,
                       visit_primitive_list, &error_abort);
- i = 0;
+
+    switch (pl_copy.type) {
[...]> +    default:
+        g_assert_not_reached();
+    }
/* compare our deserialized list of primitives to the original */
-    do {
+    i = 0;
+    while (cur_head) {
          switch (pl_copy.type) {
          case PTYPE_STRING: {
[...]
@@ -578,9 +559,9 @@ static void test_primitive_lists(gconstpointer opaque)
              g_assert_not_reached();

As both switch statements have the same 12 cases plus a default case with g_assert_not_reached(), a static code analyzer might complain that the 2nd default case will indeed never be reached because the first one already raises an assertion. So the code in the 2nd default case could be removed.

Regards,
Stefan

          }
          i++;
-    } while (cur_head);
+    }


Attachment: OpenPGP_0xE08C21D5677450AD.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to