From ccb429435e162915917f2492217c4e206b9b2a96 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 23 Dec 2016 17:13:03 +0100 Subject: blogc: common: git-receiver: improved error handling --- src/common/config-parser.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/common/config-parser.c') diff --git a/src/common/config-parser.c b/src/common/config-parser.c index ff05f2e..bfea2d4 100644 --- a/src/common/config-parser.c +++ b/src/common/config-parser.c @@ -26,7 +26,7 @@ typedef enum { bc_config_t* bc_config_parse(const char *src, size_t src_len, bc_error_t **err) { - if (err != NULL && *err != NULL) + if (err == NULL || *err != NULL) return NULL; size_t current = 0; @@ -69,9 +69,8 @@ bc_config_parse(const char *src, size_t src_len, bc_error_t **err) state = CONFIG_SECTION_KEY; continue; } - if (err != NULL) - *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len, - current, "File must start with section."); + *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len, + current, "File must start with section."); break; case CONFIG_SECTION_START: @@ -91,9 +90,8 @@ bc_config_parse(const char *src, size_t src_len, bc_error_t **err) } if (c != '\r' && c != '\n') break; - if (err != NULL) - *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len, - current, "Section names can't have new lines."); + *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len, + current, "Section names can't have new lines."); break; case CONFIG_SECTION_KEY: @@ -105,15 +103,13 @@ bc_config_parse(const char *src, size_t src_len, bc_error_t **err) if (c != '\r' && c != '\n' && !is_last) break; // key without value, should we support it? - if (err != NULL) { - size_t end = is_last && c != '\n' && c != '\r' ? src_len : - current; - key = bc_strndup(src + start, end - start); - *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len, - current, "Key without value: %s.", key); - free(key); - key = NULL; - } + size_t end = is_last && c != '\n' && c != '\r' ? src_len : + current; + key = bc_strndup(src + start, end - start); + *err = bc_error_parser(BC_ERROR_CONFIG_PARSER, src, src_len, + current, "Key without value: %s.", key); + free(key); + key = NULL; break; case CONFIG_SECTION_VALUE_START: @@ -139,7 +135,7 @@ bc_config_parse(const char *src, size_t src_len, bc_error_t **err) } - if (err != NULL && *err != NULL) { + if (*err != NULL) { bc_config_free(rv); rv = NULL; break; -- cgit v1.2.3-18-g5258