Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:41690 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48236 invoked from network); 5 Nov 2008 18:12:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2008 18:12:25 -0000 Authentication-Results: pb1.pair.com header.from=Johannes.Schlueter@Sun.COM; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 192.18.6.24 as permitted sender) X-PHP-List-Original-Sender: johannes@php.net X-Host-Fingerprint: 192.18.6.24 gmp-eb-inf-2.sun.com Solaris 10 (beta) Received: from [192.18.6.24] ([192.18.6.24:42891] helo=gmp-eb-inf-2.sun.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 66/0C-22938-FF1E1194 for ; Wed, 05 Nov 2008 13:12:25 -0500 Received: from fe-emea-09.sun.com (gmp-eb-lb-2-fe3.eu.sun.com [192.18.6.12]) by gmp-eb-inf-2.sun.com (8.13.7+Sun/8.12.9) with ESMTP id mA5IC8ns003651 for ; Wed, 5 Nov 2008 18:12:13 GMT Received: from conversion-daemon.fe-emea-09.sun.com by fe-emea-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) id <0K9V00601GXM8F00@fe-emea-09.sun.com> (original mail from johannes@php.net) for internals@lists.php.net; Wed, 05 Nov 2008 18:12:08 +0000 (GMT) Received: from [192.168.1.103] ([88.217.49.69]) by fe-emea-09.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) with ESMTPSA id <0K9V00C8MH877KF0@fe-emea-09.sun.com>; Wed, 05 Nov 2008 18:12:08 +0000 (GMT) Date: Wed, 05 Nov 2008 19:12:06 +0100 In-reply-to: <4911CA1D.7030008@lemonde.fr> Sender: Johannes.Schlueter@Sun.COM To: Olivier Grange-Labat Cc: internals@lists.php.net Message-ID: <1225908726.4251.23.camel@goldfinger.johannes.nop> MIME-version: 1.0 X-Mailer: Evolution 2.22.3.1 (2.22.3.1-1.fc9) Content-type: text/plain Content-transfer-encoding: 7BIT References: <4911CA1D.7030008@lemonde.fr> Subject: Re: [PHP-DEV] [PATCH] parse_ini_string() From: johannes@php.net (Johannes =?ISO-8859-1?Q?Schl=FCter?=) Hi, On Wed, 2008-11-05 at 17:30 +0100, Olivier Grange-Labat wrote: > Hello, > > Here's a patch again PHP_5_3 to add a parse_ini_string() function. In general I think it's good to add that function, a few comments below. > > +static > +ZEND_BEGIN_ARG_INFO_EX(arginfo_parse_ini_string, 0, 0, 1) > + ZEND_ARG_INFO(0, str) If you come up with something might a bit more verbose (same below in the prototype) [..] > +/* {{{ proto array parse_ini_string(string str [, bool > process_sections [, int scanner_mode]]) > + Parse configuration string */ > +PHP_FUNCTION(parse_ini_string) > +{ > + char *string = NULL, *str = NULL; > + int str_len = 0; please use tabs for indention, not spaces > + zend_bool process_sections = 0; > + long scanner_mode = ZEND_INI_SCANNER_NORMAL; > + zend_ini_parser_cb_t ini_parser_cb; > + > + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bl", > &str, &str_len, &process_sections, &scanner_mode) == FAILURE) { > + RETURN_FALSE; > + } > + > + /* Set callback function */ > + if (process_sections) { > + BG(active_ini_file_section) = NULL; > + ini_parser_cb = (zend_ini_parser_cb_t) > php_ini_parser_cb_with_sections; > + } else { > + ini_parser_cb = (zend_ini_parser_cb_t) > php_simple_ini_parser_cb; > + } > + > + /* Setup string */ > + string = (char *) emalloc(str_len + 1); > + strcpy(string, str); > + *(string + str_len + 1) = '\0'; Is that copy really needed? Where is the copy free'd? If doing the copy please use strlcpy instead of strcpy. About strlcpy see[1]. johannes [1] http://www.gratisoft.us/todd/papers/strlcpy.html