From 62a73ee612c7780f19b1827d5eff631c130822bd Mon Sep 17 00:00:00 2001 From: CTCaer Date: Mon, 27 Apr 2020 09:33:21 +0300 Subject: [PATCH] ini: Always clear the section allocations --- bootloader/config/ini.c | 7 ++----- bootloader/hos/pkg2_ini_kippatch.c | 19 +++++-------------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/bootloader/config/ini.c b/bootloader/config/ini.c index 85a19b1..4c200dd 100644 --- a/bootloader/config/ini.c +++ b/bootloader/config/ini.c @@ -55,12 +55,9 @@ u32 _find_section_name(char *lbuf, u32 lblen, char schar) ini_sec_t *_ini_create_section(link_t *dst, ini_sec_t *csec, char *name, u8 type) { if (csec) - { list_append(dst, &csec->link); - csec = NULL; - } - csec = (ini_sec_t *)malloc(sizeof(ini_sec_t)); + csec = (ini_sec_t *)calloc(sizeof(ini_sec_t), 1); csec->name = _strdup(name); csec->type = type; @@ -154,7 +151,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir) { u32 i = _find_section_name(lbuf, lblen, '='); - ini_kv_t *kv = (ini_kv_t *)malloc(sizeof(ini_kv_t)); + ini_kv_t *kv = (ini_kv_t *)calloc(sizeof(ini_kv_t), 1); kv->key = _strdup(&lbuf[0]); kv->val = _strdup(&lbuf[i + 1]); list_append(&csec->kvs, &kv->link); diff --git a/bootloader/hos/pkg2_ini_kippatch.c b/bootloader/hos/pkg2_ini_kippatch.c index 97d2751..fba2635 100644 --- a/bootloader/hos/pkg2_ini_kippatch.c +++ b/bootloader/hos/pkg2_ini_kippatch.c @@ -72,12 +72,9 @@ static u32 _find_patch_section_name(char *lbuf, u32 lblen, char schar) static ini_kip_sec_t *_ini_create_kip_section(link_t *dst, ini_kip_sec_t *ksec, char *name) { if (ksec) - { list_append(dst, &ksec->link); - ksec = NULL; - } - ksec = (ini_kip_sec_t *)malloc(sizeof(ini_kip_sec_t)); + ksec = (ini_kip_sec_t *)calloc(sizeof(ini_kip_sec_t), 1); u32 i = _find_patch_section_name(name, strlen(name), ':') + 1; ksec->name = _strdup(name); @@ -105,8 +102,8 @@ int ini_patch_parse(link_t *dst, char *ini_path) f_gets(lbuf, 512, &fp); lblen = strlen(lbuf); - // Remove trailing newline. - if (lbuf[lblen - 1] == '\n' || lbuf[lblen - 1] == '\r') + // Remove trailing newline. Depends on 'FF_USE_STRFUNC 2' that removes \r. + if (lblen && lbuf[lblen - 1] == '\n') lbuf[lblen - 1] = 0; if (lblen > 2 && lbuf[0] == '[') // Create new section. @@ -121,7 +118,7 @@ int ini_patch_parse(link_t *dst, char *ini_path) u32 tmp = 0; u32 i = _find_patch_section_name(lbuf, lblen, '='); - ini_patchset_t *pt = (ini_patchset_t *)malloc(sizeof(ini_patchset_t)); + ini_patchset_t *pt = (ini_patchset_t *)calloc(sizeof(ini_patchset_t), 1); pt->name = _strdup(&lbuf[1]); @@ -145,13 +142,7 @@ int ini_patch_parse(link_t *dst, char *ini_path) i += tmp + 1; pt->dstData = _htoa(NULL, &lbuf[i], pt->length); } - else - { - pt->offset = 0; - pt->length = 0; - pt->srcData = NULL; - pt->dstData = NULL; - } + list_append(&ksec->pts, &pt->link); } } while (!f_eof(&fp));