From: Bruce Richardson Date: Tue, 16 Dec 2014 15:03:53 +0000 (+0000) Subject: cfgfile: fix read of empty file X-Git-Tag: spdx-start~9942 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=d3e454a86f5f40fd66477fb032c3ce698795f18b;p=dpdk.git cfgfile: fix read of empty file 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 --- diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index f2bc2cc102..b81c2738c2 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: