[RFA] Ensure result of make_cleanup is never NULL.

Doug Evans dje@google.com
Wed Apr 18 14:32:00 GMT 2012


On Wed, Apr 18, 2012 at 7:23 AM, Pedro Alves <palves@redhat.com> wrote:
> On 04/18/2012 03:02 PM, Doug Evans wrote:
>
>> On Wed, Apr 18, 2012 at 2:26 AM, Pedro Alves <palves@redhat.com> wrote:
>>> On 04/18/2012 01:43 AM, Doug Evans wrote:
>>>
>>>> btw, I thought about making cleanup_sentinel const here, for a bit of
>>>> extra robustness.
>>>
>>>
>>> Won't that mean you'd need to cast the constness out in most, if
>>> not all places that use it?
>
>
> Well, aren't all places using the sentinel, using it throught the macro?
> What does this make more robust?


Any attempts to modify the sentinel will segv.


>>
>> --- cleanups.c= 2012-04-17 12:02:38.000000000 -0700
>> +++ cleanups.c  2012-04-18 06:59:46.000000000 -0700
>> @@ -50,10 +50,10 @@ struct cleanup
>>       [though this won't catch errors that a value of, say,
>>       ((struct cleanup *) -1) will]
>>     - displays as something useful when printed in gdb.  */
>> -static struct cleanup cleanup_sentinel;
>> +static const struct cleanup cleanup_sentinel;
>>
>>  /* Handy macro to use when referring to cleanup_sentinel.  */
>> -#define CLEANUP_SENTINEL (&cleanup_sentinel)
>> +#define CLEANUP_SENTINEL ((struct cleanup *) &cleanup_sentinel)
>>
>>  /* Chain of cleanup actions established with make_cleanup,
>>     to be executed if an error happens.  */



More information about the Gdb-patches mailing list