Bug 24864

Summary: 'struct value *v' pointer not checked in cp-valprint.c (field_is_static)
Product: gdb Reporter: Adrian Harris <adrian.harris>
Component: symtabAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: tromey
Priority: P2    
Version: 8.3.1   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Adrian Harris 2019-07-30 17:25:24 UTC
This is from the 8.3 source blob, not git.

Line 315 in cp-valprint.c has a try/catch block to catch problems with finding a static elf symbol. However, cp_print_static_field() is called regardless of the outcome and the following call chain never checks that 'v' is non-null.

The proximate fix is trivial: simply move the call into the try part of the block, e.g.:

	      else if (field_is_static (&TYPE_FIELD (type, i)))
		{
		  struct value *v = NULL;

		  TRY
		    {
		      v = value_static_field (type, i);
		      cp_print_static_field (TYPE_FIELD_TYPE (type, i),
					     v, stream, recurse + 1,
					     options);
		    }

		  CATCH (ex, RETURN_MASK_ERROR)
		    {
		      fprintf_filtered (stream,
					_("<error reading variable: %s>"),
					ex.message);
		    }
		  END_CATCH
		}

Now *why* the static symbol is not found is another question altogether, but this is clearly a bug.
Comment 1 Tom Tromey 2019-08-01 12:42:12 UTC
Thanks for the report.  This has already been fixed in git.

*** This bug has been marked as a duplicate of bug 20020 ***