X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_cfgfile%2Frte_cfgfile.c;h=002022263ea8fbd1e8c1d48298d716218ef3b7f5;hb=6b1f8e4f9b9337c81987336ae5204c7730b19d29;hp=3884151479305adc94e83283acae91602b689670;hpb=0cfffed310c30fcd9dcc837349677f4d2976270e;p=dpdk.git diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 3884151479..002022263e 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -27,7 +27,7 @@ struct rte_cfgfile { struct rte_cfgfile_section *sections; }; -static int cfgfile_logtype; +RTE_LOG_REGISTER(cfgfile_logtype, lib.cfgfile, INFO); #define CFG_LOG(level, fmt, args...) \ rte_log(RTE_LOG_ ## level, cfgfile_logtype, "%s(): " fmt "\n", \ @@ -191,7 +191,8 @@ rte_cfgfile_load_with_params(const char *filename, int flags, } /* skip parsing if comment character found */ pos = memchr(buffer, params->comment_character, len); - if (pos != NULL && (*(pos-1) != '\\')) { + if (pos != NULL && + (pos == buffer || *(pos-1) != '\\')) { *pos = '\0'; len = pos - buffer; } @@ -272,6 +273,10 @@ rte_cfgfile_create(int flags) int i; struct rte_cfgfile *cfg; + /* future proof flags usage */ + if (flags & ~(CFG_FLAG_GLOBAL_SECTION | CFG_FLAG_EMPTY_VALUES)) + return NULL; + cfg = malloc(sizeof(*cfg)); if (cfg == NULL) @@ -281,17 +286,16 @@ rte_cfgfile_create(int flags) cfg->num_sections = 0; /* allocate first batch of sections and entries */ - cfg->sections = malloc(sizeof(struct rte_cfgfile_section) * - CFG_ALLOC_SECTION_BATCH); - + cfg->sections = calloc(CFG_ALLOC_SECTION_BATCH, + sizeof(struct rte_cfgfile_section)); if (cfg->sections == NULL) goto error1; cfg->allocated_sections = CFG_ALLOC_SECTION_BATCH; for (i = 0; i < CFG_ALLOC_SECTION_BATCH; i++) { - cfg->sections[i].entries = malloc(sizeof( - struct rte_cfgfile_entry) * CFG_ALLOC_ENTRY_BATCH); + cfg->sections[i].entries = calloc(CFG_ALLOC_ENTRY_BATCH, + sizeof(struct rte_cfgfile_entry)); if (cfg->sections[i].entries == NULL) goto error1; @@ -563,10 +567,3 @@ rte_cfgfile_has_entry(struct rte_cfgfile *cfg, const char *sectionname, { return rte_cfgfile_get_entry(cfg, sectionname, entryname) != NULL; } - -RTE_INIT(cfgfile_init) -{ - cfgfile_logtype = rte_log_register("lib.cfgfile"); - if (cfgfile_logtype >= 0) - rte_log_set_level(cfgfile_logtype, RTE_LOG_INFO); -}