summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2021-06-30 09:32:35 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2021-06-30 09:32:35 -0400
commitaf1dc8eff5762cf09fda6b1cd75570814f095814 (patch)
treeb1e02822edccb25cf210ad67c09c75d59b9d7df1 /git.c
parent696bc8db36957e43756d88a093969ef16e8a4a47 (diff)
Added a check to see if `commits` is non-NULL.
Diffstat (limited to 'git.c')
-rw-r--r--git.c60
1 files 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;
}