From f9f67e8ba064afe6ec97ba446e253409c5cb3ca6 Mon Sep 17 00:00:00 2001 From: cozis Date: Mon, 9 May 2022 21:45:07 +0200 Subject: [PATCH] better error checking --- cli.c | 28 +++++++++++++++++++++------- style.css | 4 +--- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/cli.c b/cli.c index c485f64..39f3246 100644 --- a/cli.c +++ b/cli.c @@ -125,25 +125,39 @@ static int fileconv(FILE *in_fp, FILE *out_fp, } if(style_file != NULL) { + char *style_data = load_file(style_file, NULL); if(style_data == NULL) { - fprintf(stderr, "Error: Failed to open file %s\n", - style_file); + fprintf(stderr, "Error: Failed to open file %s\n", style_file); free(output); free(input); return -1; } - fputs("", out_fp); + + bool failed = fputs("", out_fp) < 0; + free(style_data); + + if(failed) { + fprintf(stderr, "Error: Failed to write to output\n"); + free(output); + free(input); + return -1; + } } - fwrite(output, 1, output_size, out_fp); // TODO: Check the return value!! + long written = fwrite(output, 1, output_size, out_fp); - /* All done! :^) */ free(output); free(input); + + if(written < output_size) { + fprintf(stderr, "Error: Failed to write to output\n"); + return -1; + } + return 0; } diff --git a/style.css b/style.css index 9341bb5..2df445a 100644 --- a/style.css +++ b/style.css @@ -72,8 +72,6 @@ */ div.c2h-code { - max-height: 600px; - padding: 10px; border-radius: 3px; @@ -97,7 +95,7 @@ div.c2h-code-inner { height: inherit; max-height: inherit; - + overflow: auto; scrollbar-color: hsla(210, 13%, 40%, 0.7) transparent; }