From af1dc8eff5762cf09fda6b1cd75570814f095814 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 30 Jun 2021 09:32:35 -0400 Subject: Added a check to see if `commits` is non-NULL. --- git.c | 60 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/git.c b/git.c index 191b800..e640f83 100644 --- a/git.c +++ b/git.c @@ -275,42 +275,46 @@ int create_pull_request_dir(pull_request *pr, int id, const char *root) { /* Get the patch files. */ commits = (pr->pr_type) ? get_branch_commits(pr->branch) : pr->patches; - /* Make patch files for each commit of PR. */ - for (int i = 0; commits[i] != NULL; i++) { - FILE *fp; - /* Does this patch file exists? */ - if (access(commits[i]->name, F_OK) == 0) { - long size = 0; - char *buf = read_file(commits[i]->name, &size); - log(LOG_NOTICE, "Patch file %s already exists.", commits[i]->name); - /* Did we read the file? */ - if (buf != NULL) { - /* Are the contents of the patch file the same? */ - if (strcmp(commits[i]->buf, buf) == 0) { - /* Skip creating this patch file. */ - log(LOG_NOTICE, "Patch file %s is the same as the new one.", commits[i]->name); + /* Is the patch file array non-NULL? */ + if (commits != NULL) { + /* Make patch files for each commit of PR. */ + for (int i = 0; commits[i] != NULL; i++) { + FILE *fp; + /* Does this patch file exists? */ + if (access(commits[i]->name, F_OK) == 0) { + long size = 0; + char *buf = read_file(commits[i]->name, &size); + log(LOG_NOTICE, "Patch file %s already exists.", commits[i]->name); + /* Did we read the file? */ + if (buf != NULL) { + /* Are the contents of the patch file the same? */ + if (strcmp(commits[i]->buf, buf) == 0) { + /* Skip creating this patch file. */ + log(LOG_NOTICE, "Patch file %s is the same as the new one.", commits[i]->name); + free(buf); + continue; + } free(buf); + } else { + log(LOG_WARNING, "Couldn't open patch file %s.", commits[i]->name); continue; } - free(buf); - } else { - log(LOG_WARNING, "Couldn't open patch file %s.", commits[i]->name); - continue; } + + /* Create the format patch file for this commit. */ + fp = fopen(commits[i]->name, "w"); + fwrite(commits[i]->buf, sizeof(char), strlen(commits[i]->buf), fp); + fclose(fp); } - /* Create the format patch file for this commit. */ - fp = fopen(commits[i]->name, "w"); - fwrite(commits[i]->buf, sizeof(char), strlen(commits[i]->buf), fp); - fclose(fp); + if (commits != NULL && pr->pr_type) { + free_files(commits); + } + } else { + log(LOG_ERR, "Patch file array is NULL."); + ret = -1; } - free(pr_dir); - - if (pr->pr_type) { - free_files(commits); - } - return ret; } -- cgit v1.2.3-13-gbd6f