tests: varlocs workaround format-overflow errors 03/277303/1 accepted/tizen_6.5_base accepted/tizen_6.5_base_tool tizen_6.5_base accepted/tizen/6.5/base/20230714.002451 accepted/tizen/6.5/base/tool/20220718.041308 submit/tizen_6.5_base/20220706.012634 submit/tizen_6.5_base/20220715.044632
authorMark Wielaard <mark@klomp.org>
Sat, 4 Dec 2021 00:18:42 +0000 (01:18 +0100)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 5 Jul 2022 01:40:56 +0000 (10:40 +0900)
In function ‘printf’,
    inlined from ‘handle_attr’ at varlocs.c:932:3:
error: ‘%s’ directive argument is null [-Werror=format-overflow=]

The warning is technically correct. A %s argument should not be
NULL. Although in practice all implementations will print it as
"(null)". Workaround this by simply changing the dwarf string
functions to return an "<unknown>" string. The test is for the correct
names, either "(null)" or "<unknown>" would make it fail (also remove
a now unnecessary assert, the switch statement will check for unknown
opcodes anyway).

Signed-off-by: Mark Wielaard <mark@klomp.org>
[sw0312.kim: partially pick upstream commit fd2cadbe4749f43551f7df90ee41837d83a6fbc4
   to fix build warning except src/ChangeLog]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I52273c671e9ecea250135096629e708163c5aa16

tests/varlocs.c

index 4050519..1d68594 100644 (file)
@@ -76,7 +76,7 @@ dwarf_encoding_string (unsigned int code)
   if (likely (code < sizeof (known) / sizeof (known[0])))
     return known[code];
 
-  return NULL;
+  return "<unknown encoding>";
 }
 
 static const char *
@@ -88,7 +88,7 @@ dwarf_tag_string (unsigned int tag)
       DWARF_ALL_KNOWN_DW_TAG
 #undef DWARF_ONE_KNOWN_DW_TAG
     default:
-      return NULL;
+      return "<unknown tag>";
     }
 }
 
@@ -101,7 +101,7 @@ dwarf_attr_string (unsigned int attrnum)
       DWARF_ALL_KNOWN_DW_AT
 #undef DWARF_ONE_KNOWN_DW_AT
     default:
-      return NULL;
+      return "<unknown attr>";
     }
 }
 
@@ -114,7 +114,7 @@ dwarf_form_string (unsigned int form)
       DWARF_ALL_KNOWN_DW_FORM
 #undef DWARF_ONE_KNOWN_DW_FORM
     default:
-      return NULL;
+      return "<unknown form>";
     }
 }
 
@@ -160,7 +160,7 @@ dwarf_opcode_string (unsigned int code)
   if (likely (code < sizeof (known) / sizeof (known[0])))
     return known[code];
 
-  return NULL;
+  return "<unknown opcode>";
 }
 
 // Forward reference for print_expr_block.
@@ -198,7 +198,6 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr, int depth)
 
   uint8_t atom = expr->atom;
   const char *opname = dwarf_opcode_string (atom);
-  assert (opname != NULL);
 
   switch (atom)
     {