From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id 8F4D35323 for ; Wed, 29 Jan 2014 23:16:24 +0100 (CET) Received: from was59-1-82-226-113-214.fbx.proxad.net ([82.226.113.214] helo=[192.168.0.11]) by mail.droids-corp.org with esmtpsa (TLS1.0:DHE_RSA_CAMELLIA_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1W8dSn-0004lw-II; Wed, 29 Jan 2014 23:18:32 +0100 Message-ID: <52E97DFE.2060505@6wind.com> Date: Wed, 29 Jan 2014 23:17:34 +0100 From: Olivier MATZ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: "Richardson, Bruce" References: <1390925204-10800-1-git-send-email-olivier.matz@6wind.com> <1390925204-10800-7-git-send-email-olivier.matz@6wind.com> <59AF69C657FD0841A61C55336867B5B01A995C12@IRSMSX103.ger.corp.intel.com> In-Reply-To: <59AF69C657FD0841A61C55336867B5B01A995C12@IRSMSX103.ger.corp.intel.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH 06/11] kvargs: simpler parsing and allow duplicated keys X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jan 2014 22:16:25 -0000 Hi Bruce, >> Also replace rte_strsplit() by more a standard function strtok_r() that is >> easier to understand for people already knowing the libc. It also avoids >> useless calls to strnlen(). The delimiters macros become strings instead of >> chars due to the strtok_r() API. >> > > As a general rule, we try to use only string functions which > track the buffer length they are working with, which is why the > function rte_strsplit() is used. While strtok_r() is indeed a > standard C function, why not use the code as originally written? Thank you for your comment. Another reason for not using rte_strsplit() is that the buffer length argument that was given was not relevant. Indeed, the string we want to parse initially comes from the command line arguments, which is duplicated with strdup(). It is not stored in a fixed size buffer. In my opinion, giving strnlen(pairs[i], MAX_ARG_STRLEN) as the size to rte_strsplit() would not prevent the program to a segfault or to read a corrupted string if it is not properly null-terminated. Does it makes sense ? Regards Olivier