Commit e7604da800f19b16d7b6b8281068313a993a90b9

Edward Thomson 2020-04-05T14:51:56

config: use GIT_ASSERT

diff --git a/src/config.c b/src/config.c
index b3e7324..a6a8cb2 100644
--- a/src/config.c
+++ b/src/config.c
@@ -108,7 +108,8 @@ int git_config_add_file_ondisk(
 	struct stat st;
 	int res;
 
-	assert(cfg && path);
+	GIT_ASSERT_ARG(cfg);
+	GIT_ASSERT_ARG(path);
 
 	res = p_stat(path, &st);
 	if (res < 0 && errno != ENOENT && errno != ENOTDIR) {
@@ -316,7 +317,8 @@ int git_config_add_backend(
 	backend_internal *internal;
 	int result;
 
-	assert(cfg && backend);
+	GIT_ASSERT_ARG(cfg);
+	GIT_ASSERT_ARG(backend);
 
 	GIT_ERROR_CHECK_VERSION(backend, GIT_CONFIG_BACKEND_VERSION, "git_config_backend");
 
@@ -514,7 +516,8 @@ int git_config_backend_foreach_match(
 	git_regexp regex;
 	int error = 0;
 
-	assert(backend && cb);
+	GIT_ASSERT_ARG(backend);
+	GIT_ASSERT_ARG(cb);
 
 	if (regexp && git_regexp_compile(&regex, regexp, 0) < 0)
 		return -1;
@@ -1197,7 +1200,7 @@ int git_config_lock(git_transaction **out, git_config *cfg)
 	git_config_backend *backend;
 	backend_internal *internal;
 
-	assert(cfg);
+	GIT_ASSERT_ARG(cfg);
 
 	internal = git_vector_get(&cfg->backends, 0);
 	if (!internal || !internal->backend) {
@@ -1217,7 +1220,7 @@ int git_config_unlock(git_config *cfg, int commit)
 	git_config_backend *backend;
 	backend_internal *internal;
 
-	assert(cfg);
+	GIT_ASSERT_ARG(cfg);
 
 	internal = git_vector_get(&cfg->backends, 0);
 	if (!internal || !internal->backend) {
@@ -1377,7 +1380,8 @@ int git_config_parse_path(git_buf *out, const char *value)
 {
 	int error;
 
-	assert(out && value);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(value);
 
 	if ((error = git_buf_sanitize(out)) < 0)
 		return error;
@@ -1423,7 +1427,8 @@ int git_config__normalize_name(const char *in, char **out)
 {
 	char *name, *fdot, *ldot;
 
-	assert(in && out);
+	GIT_ASSERT_ARG(in);
+	GIT_ASSERT_ARG(out);
 
 	name = git__strdup(in);
 	GIT_ERROR_CHECK_ALLOC(name);
diff --git a/src/config_file.c b/src/config_file.c
index b1e0028..7fba71a 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -365,7 +365,7 @@ static int config_file_set_multivar(
 	int result;
 	char *key;
 
-	assert(regexp);
+	GIT_ASSERT_ARG(regexp);
 
 	if ((result = git_config__normalize_name(name, &key)) < 0)
 		return result;
@@ -531,7 +531,7 @@ static char *escape_value(const char *ptr)
 	size_t len;
 	const char *esc;
 
-	assert(ptr);
+	GIT_ASSERT_ARG_WITH_RETVAL(ptr, NULL);
 
 	len = strlen(ptr);
 	if (!len)
diff --git a/src/config_parse.c b/src/config_parse.c
index ed2c87f..7da92d3 100644
--- a/src/config_parse.c
+++ b/src/config_parse.c
@@ -187,7 +187,7 @@ static int parse_section_header(git_config_parser *reader, char **section_out)
 
 	/* Make sure we were given a section header */
 	c = line[pos++];
-	assert(c == '[');
+	GIT_ASSERT(c == '[');
 
 	c = line[pos++];