From 6fec7170544009fe3ce95b0d2b7e6ab65c97922d Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sun, 24 Jul 2022 20:33:41 -0300 Subject: git: Remove reason string reference from `is_valid_index()` --- git.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/git.c b/git.c index af188d7..ff3a574 100644 --- a/git.c +++ b/git.c @@ -284,7 +284,7 @@ file **get_branch_commits(git_branch *br) { return NULL; } -int is_valid_index(index *idx, char **reason) { +int is_valid_index(index *idx) { int did_alloc = 0; char *err_str = NULL; @@ -303,13 +303,16 @@ int is_valid_index(index *idx, char **reason) { /* Did we get an error? */ if (err_str != NULL) { - *reason = err_str; - /* Return -1 if error string was allocated, and false if not. */ - return (did_alloc) ? -1 : 0; + log_reason(LOG_ERR, "Invalid index.", reason); + if (did_alloc) { + free(err_str); + } + /* Invalid index, return false. */ + return 0; /* Is there another index after this one? */ } else if (idx->next != NULL) { /* Return the validity of the next index. */ - return is_valid_index(idx->next, reason); + return is_valid_index(idx->next); } /* Valid index, return true. */ return 1; @@ -320,13 +323,7 @@ char *make_index_path(const char *root, index *idx, int path_type) { char *tmp; int path_len = strlen(root) + 1; /* Is the index invalid? */ - const int valid_index = is_valid_index(idx, &reason); - if (valid_index <= 0) { - log_reason(LOG_NOTICE, "Invalid index.", reason); - /* Was the reason string allocated? */ - if (valid_index < 0) { - free(reason); - } + if (!is_valid_index(idx)) { return NULL; } -- cgit v1.2.3-13-gbd6f