git-off

git off handles large files in git repos
git clone https://noulin.net/git/git-off.git
Log | Files | Refs | README

commit 73cc11fb73df826588db3ca19b94a48f493ddc79
parent ddc6c3cf8b05c4f1c3adcb8c95cd7eabd2e1803f
Author: Remy Noulin <loader2x@gmail.com>
Date:   Tue, 20 Dec 2016 08:32:12 +0100

fix bugs found by running clang and cppcheck

c/gitoff.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)

Diffstat:
Mc/gitoff.c | 31++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/c/gitoff.c b/c/gitoff.c @@ -497,6 +497,9 @@ char **execOut(char *cmd) { } else { list = realloc(list, (count+2) * sizeof(int *)); + if (list == NULL) { + exit(EXIT_FAILURE); + } list[count+1] = NULL; } list[count] = strdup(line); @@ -552,6 +555,9 @@ char **split(char *string, char* delim) { } else { r = realloc(r, (count+2) * sizeof(int *)); + if (r == NULL) { + exit(EXIT_FAILURE); + } r[count+1] = NULL; } r[count] = strdup(token); @@ -1288,34 +1294,41 @@ void transportHttpReceive(char *file) { } void offHelpers_setTransport(char *mode ) { + char *m = NULL; // set send and receive functions for transport // copy, scp // use mode from config or from parameter if (strcmp(mode, "config") == 0) { - mode = strdup(offHelpers_offMode()); + m = strdup(offHelpers_offMode()); + } + else { + m = mode; } // copy mode - if (strcmp(mode, "copy") == 0) { + if (strcmp(m, "copy") == 0) { transport.send = transportCopySend; transport.receive = transportCopyReceive; } // scp mode - else if (strcmp(mode, "scp") == 0) { + else if (strcmp(m, "scp") == 0) { transport.send = transportScpSend; transport.receive = transportScpReceive; } // http mode - else if (strcmp(mode, "http") == 0) { + else if (strcmp(m, "http") == 0) { transport.send = transportHttpSend; transport.receive = transportHttpReceive; -} } + if (m != mode) { + free(m); +} + } // // // s3 mode // else if mode == 's3' @@ -1463,6 +1476,7 @@ void transport_transformFrom(char *file) { sprintf(cmd, "%s%s%s", cmd2, p2, tmp+3); free(p2); //print cmd + free(cmd2); freeList((void **)offFilePath); offFilePath = execOut(cmd); freeList((void **)offFilePath); @@ -1713,7 +1727,7 @@ void offCommands_configAlways() { gitConfig_set(COMMAND_GITCONFIG[configAlwaysC], argv[argc-1]); } else { - printf("%s %s", COMMAND_GITCONFIG[configAlwaysC], COMMAND_HELPERS[configAlwaysC]); + printf("%s %s", COMMAND_GITCONFIG[configAlwaysC], COMMAND_HELPERS[configAlwaysC]()); printf("\n"); } } @@ -1859,7 +1873,7 @@ void offCommands_clean() { // print git off ref to stdout for git // ### git-off v1 sha:be3e02b60effe3eab232d5590a6a2e2c2c2f443b size:119 char sst[20]; - sprintf(sst,"%d", size); + sprintf(sst,"%lu", size); char *tmp; tmp = malloc(strlen(offDEFAULTS[offSignatureD]) + strlen(offFile) + strlen(sst) + 1 + 6); sprintf(tmp, "%s%s size:%s", offDEFAULTS[offSignatureD], offFile, sst); @@ -1897,6 +1911,9 @@ void offCommands_prepush() { } else { list = realloc(list, (count+2) * sizeof(int *)); + if (list == NULL) { + exit(EXIT_FAILURE); + } list[count+1] = NULL; } list[count] = strdup(line);