fprintf: Do not scrub type when looking up its type

As we end up goto'ing to a place where we need that original type and
were having just a NULL pointer, oops, fix it.

Related to:

  Error: NULL_RETURNS (CWE-476): [#def18]
  dwarves-1.13/dwarves_fprintf.c:727: returned_null: "cu__type" returns "NULL" (checked 54 out of 62 times).
  dwarves-1.13/dwarves_fprintf.c:727: var_assigned: Assigning: "type" = "NULL" return value from "cu__type".
  dwarves-1.13/dwarves_fprintf.c:686: dereference: Dereferencing "type", which is known to be "NULL".
  dwarves-1.13/codiff.c:137: example_assign: Example 1: Assigning: "old_type" = return value from "cu__type(old_cu, old->tag.type)".
  dwarves-1.13/codiff.c:141: example_checked: Example 1 (cont.): "old_type" has its value checked in "old_type == NULL".
  dwarves-1.13/ctracer.c:356: example_assign: Example 2: Assigning: "type" = return value from "cu__type(cu, tag->type)".
  dwarves-1.13/ctracer.c:358: example_checked: Example 2 (cont.): "type" has its value checked in "type == NULL".
  dwarves-1.13/dwarves.c:914: example_assign: Example 3: Assigning: "type" = return value from "cu__type(cu, tag->type)".
  dwarves-1.13/dwarves.c:916: example_checked: Example 3 (cont.): "type" has its value checked in "type == NULL".
  dwarves-1.13/dwarves.c:941: example_assign: Example 4: Assigning: "tag" = return value from "cu__type(cu, var->ip.tag.type)".
  dwarves-1.13/dwarves.c:942: example_checked: Example 4 (cont.): "tag" has its value checked in "tag != NULL".
  dwarves-1.13/dwarves_emit.c:139: example_assign: Example 5: Assigning: "ptr_type" = return value from "cu__type(cu, type->type)".
  dwarves-1.13/dwarves_emit.c:141: example_checked: Example 5 (cont.): "ptr_type" has its value checked in "ptr_type == NULL".
  #  684|
  #  685|   next_type:
  #  686|-> 	switch (type->tag) {
  #  687|   	case DW_TAG_pointer_type:
  #  688|

Reported-by: William Cohen <wcohen@redhat.com>
Fixes: 568dae4bd4 ("printf: Fixup printing "const" early with "const void"")
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-07-02 10:42:52 -03:00
parent e95dacb704
commit e737976c09
1 changed files with 6 additions and 3 deletions

View File

@ -724,10 +724,13 @@ print_default:
size_t const_printed = fprintf(fp, "%s ", "const");
tconf.type_spacing -= const_printed;
printed += const_printed;
}
type = cu__type(cu, type->type);
if (type)
struct tag *ttype = cu__type(cu, type->type);
if (ttype) {
type = ttype;
goto next_type;
}
}
goto print_default;
case DW_TAG_array_type: