diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 796cfcc6147c062e32c1479a6b74dbf40e21f25c
parent b18d6ccf708fc010f85b016315de614b354bc9df
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Wed, 29 Dec 2021 22:07:17 +0100

rename variable and use calloc

Diffstat:
Msrc/export.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/export.c b/src/export.c @@ -70,25 +70,24 @@ void ics_export(const char* ics_filepath, WINDOW* header, WINDOW* cal, WINDOW* a descr_bytes = ftell(fp); rewind(fp); - size_t descr_labell = strlen("DESCRIPTION:"); - size_t descr_size = descr_bytes + descr_labell + 1; - descr = malloc(descr_size); + size_t descr_label_size = strlen("DESCRIPTION:"); + size_t descr_size = descr_bytes + descr_label_size; + descr = calloc(descr_size + 1, sizeof(char)); if (descr == NULL) { perror("malloc failed"); return; } - descr[0] = '\0'; strcat(descr, "DESCRIPTION:"); // read description bytes from journal entry file and append to descr - int items_read = fread(descr + descr_labell, sizeof(char), descr_bytes, fp); + int items_read = fread(descr + descr_label_size, sizeof(char), descr_bytes, fp); if (items_read != descr_bytes) { fprintf(stderr, "Read %i items but expected %li, aborting.", items_read, descr_bytes); return; } - descr[descr_size - 1] = '\0'; + descr[descr_size] = '\0'; char* folded_descr = fold(descr);