From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id B29477E79 for ; Tue, 16 Dec 2014 16:05:15 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 16 Dec 2014 07:01:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,691,1406617200"; d="scan'208";a="499566219" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga003.jf.intel.com with ESMTP; 16 Dec 2014 06:59:43 -0800 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id sBGF3sUG008303; Tue, 16 Dec 2014 15:03:54 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id sBGF3s2K016853; Tue, 16 Dec 2014 15:03:54 GMT Received: (from bricha3@localhost) by sivswdev01.ir.intel.com with id sBGF3sUx016847; Tue, 16 Dec 2014 15:03:54 GMT From: Bruce Richardson To: dev@dpdk.org Date: Tue, 16 Dec 2014 15:03:53 +0000 Message-Id: <1418742233-16776-6-git-send-email-bruce.richardson@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1418742233-16776-1-git-send-email-bruce.richardson@intel.com> References: <1418742233-16776-1-git-send-email-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH 5/5] cfgfile: prevent error when reading an empty file 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: Tue, 16 Dec 2014 15:05:18 -0000 If the file to be read by the cfgfile is empty, i.e. no configuration data, but possibly comments present, the cfgfile should not mark the last processed section (curr_section) as having N entries, since there is no last processed section. Signed-off-by: Bruce Richardson --- lib/librte_cfgfile/rte_cfgfile.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index f2bc2cc..b81c273 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -225,8 +225,10 @@ rte_cfgfile_load(const char *filename, int flags) } fclose(f); cfg->flags = flags; - cfg->sections[curr_section]->num_entries = curr_entry + 1; cfg->num_sections = curr_section + 1; + /* curr_section will still be -1 if we have an empty file */ + if (curr_section >= 0) + cfg->sections[curr_section]->num_entries = curr_entry + 1; return cfg; error1: -- 1.9.3