From 498b475df6e318d83280f119af649f02c7f1fd9a Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Sat, 13 Aug 2016 09:18:49 +1000 Subject: [PATCH] fix some bugs in ticproc --- utils/ticproc/ticproc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/utils/ticproc/ticproc.c b/utils/ticproc/ticproc.c index d993aa2..dbeb796 100644 --- a/utils/ticproc/ticproc.c +++ b/utils/ticproc/ticproc.c @@ -79,7 +79,7 @@ int copy_file(char *src, char *dest) { return -1; } dest_file = fopen(dest, "wb"); - if (!src_file) { + if (!dest_file) { fclose(src_file); return -1; } @@ -182,6 +182,11 @@ int add_file(struct ticfile_t *ticfile) { // check crc fptr = fopen(src_filename, "rb"); + if (!fptr) { + sqlite3_free(err_msg); + sqlite3_close(db); + return -1; + } if (Crc32_ComputeFile(fptr, &crc) == -1) { fprintf(stderr, "Error computing CRC\n"); sqlite3_close(db); @@ -270,9 +275,9 @@ int add_file(struct ticfile_t *ticfile) { desc_len += strlen(ticfile->desc[j]) + 1; } - description = (char *)malloc(desc_len); + description = (char *)malloc(desc_len + 1); - memset(description, 0, desc_len); + memset(description, 0, desc_len + 1); for (j=0;jdesc_lines;j++) { strcat(description, ticfile->desc[j]);