aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-12-23 17:13:03 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-12-23 17:13:03 +0100
commitccb429435e162915917f2492217c4e206b9b2a96 (patch)
tree5aca18649cd45f2583593ff5799e9512c1960eb2 /src/common
parentb9ec274bed571db9c705b65bb8c0bb6409c34fc4 (diff)
downloadblogc-ccb429435e162915917f2492217c4e206b9b2a96.tar.gz
blogc-ccb429435e162915917f2492217c4e206b9b2a96.tar.bz2
blogc-ccb429435e162915917f2492217c4e206b9b2a96.zip
blogc: common: git-receiver: improved error handling
Diffstat (limited to 'src/common')
-rw-r--r--src/common/config-parser.c30
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;