slweb

Једноставни генератор статичких веб страна
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување fc32c197457ac7f66583de7d4380ba31e7844d9e
родитељ 841ccb2a55622a01cc81026397f5fe59cf1c6e8e
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Tue,  5 Oct 2021 15:24:38 +0200

Remove unnecessary checks

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mdefs.h | 2++
Mslweb.c | 44+++++++++++++++-----------------------------
измењених датотека: 2, додавања: 17(+), брисања: 29(-)

diff --git a/defs.h b/defs.h @@ -57,6 +57,8 @@ typedef enum #define ANY(var, mask) (((var) & (mask)) != 0) #define IN(var, mask) ALL(var, mask) +#define MIN(a,b) ((a < b) ? (a) : (b)) + typedef unsigned char UBYTE; typedef unsigned long ULONG; typedef unsigned long long ULLONG; diff --git a/slweb.c b/slweb.c @@ -139,10 +139,8 @@ free_keyvalue(KeyValue** list, const size_t list_count) for (size_t index = 0; index < list_count; index++) { KeyValue* current = *list + index; - if (current->value) - free(current->value); - if (current->key) - free(current->key); + free(current->value); + free(current->key); } return 0; } @@ -150,25 +148,19 @@ free_keyvalue(KeyValue** list, const size_t list_count) int slweb_cleanup() { - if (basedir) - free(basedir); + free(basedir); free(input_dirname); while (inline_footnote_count--) free(inline_footnotes[inline_footnote_count]); - if (inline_footnotes) - free(inline_footnotes); + free(inline_footnotes); free_keyvalue(&footnotes, footnote_count); free_keyvalue(&links, links_count); free_keyvalue(&macros, macros_count); free_keyvalue(&vars, vars_count); - if (footnotes) - free(footnotes); - if (links) - free(links); - if (macros) - free(macros); - if (vars) - free(vars); + free(footnotes); + free(links); + free(macros); + free(vars); return 0; } @@ -444,14 +436,12 @@ read_file_into_buffer(FILE** input, u8** buffer, size_t* buffer_size, return error(ENOENT, (u8*)"No such file: %s", input_filename); fstat(fileno(*input), &fs); - if (*buffer) - free(*buffer); + free(*buffer); *buffer_size = fs.st_size + 1; CALLOC(*buffer, u8, *buffer_size); fread((void*)*buffer, 1, *buffer_size, *input); - if (*input_dirname) - free(*input_dirname); + free(*input_dirname); slash = strrchr(input_filename, '/'); if (slash) @@ -1291,8 +1281,7 @@ process_include(FILE* output, const u8* token, while (inline_footnote_count--) free(inline_footnotes[inline_footnote_count]); - if (inline_footnotes) - free(inline_footnotes); + free(inline_footnotes); inline_footnotes = NULL; inline_footnote_count = 0; current_inline_footnote = 0; @@ -1470,7 +1459,7 @@ process_incdir_subdir(FILE* output, const char* subdirname, pnamelist = namelist; names_output = 0; - while (names_output < names_total && pnamelist && *pnamelist) + while (names_output < names_total) { int pstatus = 0; @@ -1510,8 +1499,7 @@ process_incdir_subdir(FILE* output, const char* subdirname, while (inline_footnote_count--) free(inline_footnotes[inline_footnote_count]); - if (inline_footnotes) - free(inline_footnotes); + free(inline_footnotes); inline_footnotes = NULL; inline_footnote_count = 0; current_inline_footnote = 0; @@ -1651,7 +1639,7 @@ process_incdir(FILE* output, const u8* token, const u8* link_prefix, pnamelist = namelist; names_output = 0; - while (names_output < num && pnamelist && *pnamelist) + while (names_output < MIN(names_total,num)) { process_incdir_subdir(output, (*pnamelist)->d_name, link_prefix, details_open, macro_body); @@ -4760,9 +4748,7 @@ done_buffer: if (!read_yaml_macros_and_links && !body_only) end_body_and_html(output); - if (link_text) - free(link_text); - + free(link_text); free(link_macro); free(token); free(line);