diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/config-parser.c | 30 |
1 files changed, 13 insertions, 17 deletions
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; |