This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Extend SystemTap SDT probe argument parser
- From: Sergio Durigan Junior <sergiodj at redhat dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: GDB Patches <gdb-patches at sourceware dot org>
- Date: Tue, 17 Dec 2013 19:06:48 -0200
- Subject: Re: [PATCH] Extend SystemTap SDT probe argument parser
- Authentication-results: sourceware.org; auth=none
- References: <1386734160-29837-1-git-send-email-sergiodj at redhat dot com> <52B02F82 dot 3020907 at redhat dot com> <m37gb3wfoi dot fsf at redhat dot com> <52B0AA0E dot 9020302 at redhat dot com>
On Tuesday, December 17 2013, Pedro Alves wrote:
> On 12/17/2013 05:27 PM, Sergio Durigan Junior wrote:
>> +/* Helper function to print a list of strings, represented as "const
>> + char *const *". The list is printed comma-separated. */
>> +
>> +static char *
>> +pstring_list (const char *const *list)
>> +{
>> + static char ret[100];
>> + const char *const *p;
>> + size_t offset = 0;
>> +
>> + if (list == NULL)
>> + return "(null)";
>> +
>> + ret[0] = '\0';
>> + for (p = list; *p != NULL && offset < sizeof (ret); ++p)
>> + {
>> + size_t s = xsnprintf (ret + offset, sizeof (ret) - offset, "%s, ", *p);
>> + offset += 2 + s;
>> + }
>> +
>> + gdb_assert (offset - 2 < sizeof (ret));
>
> Note this will assert if the list is empty (but not NULL), i.e., { NULL },
> because offset will be 0, and "offset - 2" will wrap around
> (offset is unsigned size_t.) I suggest either moving the assert within
> the if below, or handle that case especially, printing "(empty)"
> or some such.
Thanks, nice catch. I moved the assert within the "if".
--
Sergio