diary

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

commit 914935013b5270f557aacff5d30fbb17cf1f2af3
parent 796cfcc6147c062e32c1479a6b74dbf40e21f25c
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Wed, 29 Dec 2021 22:33:23 +0100

fix(caldav): use calloc, one-off null

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

diff --git a/src/caldav.c b/src/caldav.c @@ -530,24 +530,23 @@ void put_event(struct tm* date, const char* dir, size_t dir_size, char* calendar descr_bytes = ftell(fp); rewind(fp); - size_t descr_labell = strlen("DESCRIPTION:"); - size_t descrl = descr_bytes + descr_labell + 1; - descr = malloc(descrl); + 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:"); - 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[descrl] = '\0'; + descr[descr_size] = '\0'; fprintf(stderr, "File buffer that will be uploaded to the remote CalDAV server:\n%s\n", descr); char* folded_descr = fold(descr);