From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24488 invoked by alias); 17 Dec 2013 21:06:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 24478 invoked by uid 89); 17 Dec 2013 21:06:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 17 Dec 2013 21:06:55 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBHL6q0V004027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Dec 2013 16:06:52 -0500 Received: from psique (ovpn-113-148.phx2.redhat.com [10.3.113.148]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBHL6nEo031907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 17 Dec 2013 16:06:51 -0500 From: Sergio Durigan Junior To: Pedro Alves Cc: GDB Patches Subject: Re: [PATCH] Extend SystemTap SDT probe argument parser References: <1386734160-29837-1-git-send-email-sergiodj@redhat.com> <52B02F82.3020907@redhat.com> <52B0AA0E.9020302@redhat.com> X-URL: http://www.redhat.com Date: Tue, 17 Dec 2013 21:06:00 -0000 In-Reply-To: <52B0AA0E.9020302@redhat.com> (Pedro Alves's message of "Tue, 17 Dec 2013 19:46:22 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2013-12/txt/msg00665.txt.bz2 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