From: Ian Jackson Subject: Re: [PATCH v6 for-4.5 4/5] xl: add 'trim' and 'split_string_into_pair' functions Date: Fri, 26 Sep 2014 16:45:30 +0100 Message-ID: <21541.35354.847047.887012@mariner.uk.xensource.com> References: <1411591685-25308-1-git-send-email-dave.scott@citrix.com> <1411591685-25308-5-git-send-email-dave.scott@citrix.com> <20140926100917.GD12753@zion.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XXXiF-0001dD-Po for xen-devel@lists.xenproject.org; Fri, 26 Sep 2014 15:45:39 +0000 In-Reply-To: <20140926100917.GD12753@zion.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Wei Liu Cc: xen-devel@lists.xenproject.org, David Scott , ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org Wei Liu writes ("Re: [PATCH v6 for-4.5 4/5] xl: add 'trim' and 'split_string_into_pair' functions"): > On Wed, Sep 24, 2014 at 09:48:04PM +0100, David Scott wrote: > > +/* NB: this follows the interface used by . See 'man 3 ctype' > > + and look for CTYPE in libxl_internal.h */ > > +typedef int (*char_predicate_t)(const int c); > > + > > +static void trim(char_predicate_t predicate, const char *input, char **output) __attribute__ ((unused)); > > +static void trim(char_predicate_t predicate, const char *input, char **output) > > +{ > > + char *p, *q, *tmp; > > Ideally you should check input != NULL before dereferencing it. Or you > need to document this function expects a valid pointer. (Thanks for looking at this, Wei, but:) I disagree. I think in general a function that takes any kind of pointer should be assumed to require a non-NULL pointer. It should not carry out any kind of nullness check; it should just dereference the pointer (and consequently crash if it is NULL). If a function permits callers to pass NULL, that should be documented in the function's doc comment (along, presumably, with the semantics, if that isn't obvious). > You didn't restrict number of entries in this function. So a malformed > "a=b=c" string ends up with "a" in key and "b=c" in value. Is that a > problem? That seems desirable to me. Otherwise `=' becomes another character that can't be specified in a value. Ian.