[PATCH] Fix faulty use of obstack_free() to *shrink* dont_print_statmem_obstack. Instead use obstack_blank_fast() with a "negative" size. A real stack data structured would be appropriate here. Added unit test gdb/testsuite/gdb.cp/printstaticrecursion.exp.

Simon Marchi simon.marchi@ericsson.com
Mon Oct 23 17:17:00 GMT 2017


On 2017-10-23 12:09 PM, Simon Marchi wrote:
>> diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
>> index fb9bfd9..8f9658d 100644
>> --- a/gdb/cp-valprint.c
>> +++ b/gdb/cp-valprint.c
>> @@ -370,14 +370,9 @@ cp_print_value_fields (struct type *type, struct type *real_type,
>>  
>>  	  if (obstack_final_size > statmem_obstack_initial_size)
>>  	    {
>> -	      /* In effect, a pop of the printed-statics stack.  */
>> -
>> -	      void *free_to_ptr =
>> -		(char *) obstack_next_free (&dont_print_statmem_obstack) -
>> -		(obstack_final_size - statmem_obstack_initial_size);
>> -
>> -	      obstack_free (&dont_print_statmem_obstack,
>> -			    free_to_ptr);
>> +          /* In effect, a pop of the printed-statics stack.  */
>> +          size_t shrink_bytes = statmem_obstack_initial_size - obstack_final_size;

Hmm, size_t is unsigned, maybe it would be better to use ssize_t?

>> +          obstack_blank_fast(&dont_print_statmem_obstack, shrink_bytes);
> 
> The indentation should be 1 tab + 6 spaces.
> 
>>  	    }
>>  
>>  	  if (last_set_recurse != recurse)
> 
> The code below that (which seems to be handling a similar situation, but for arrays) uses
> obstack_next_free as well.  Is there the same problem there?

Never mind about this, I saw your other message after reading this one.

Simon



More information about the Gdb-patches mailing list