commit 0c29f1c9ed52ac60b5bc5f74a7840d1f23b96b71
parent a887c540b0ba320479e66b4517f52bf96943ddc7
Author: Frederic Cambus <fred@statdns.com>
Date: Thu, 13 Dec 2018 00:41:11 +0100
Add error handling for ansilove_init() and ansilove_{load|save}file()
Diffstat:
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/main.c b/src/main.c
@@ -89,7 +89,10 @@ main(int argc, char *argv[])
const char *errstr;
- ansilove_init(&ctx, &options);
+ if (ansilove_init(&ctx, &options) == -1) {
+ fprintf(stderr, "\n%s\n", ansilove_error(&ctx));
+ return EXIT_FAILURE;
+ }
if (pledge("stdio cpath rpath wpath", NULL) == -1) {
err(EXIT_FAILURE, "pledge");
@@ -221,7 +224,10 @@ main(int argc, char *argv[])
if (!strcmp(fext, ".diz"))
options.diz = true;
- ansilove_loadfile(&ctx, input);
+ if (ansilove_loadfile(&ctx, input) == -1) {
+ fprintf(stderr, "\n%s\n", ansilove_error(&ctx));
+ return EXIT_FAILURE;
+ }
/* adjust the file size if file contains a SAUCE record */
if (fileHasSAUCE) {
@@ -251,7 +257,10 @@ main(int argc, char *argv[])
}
/* create the output file */
- ansilove_savefile(&ctx, fileName);
+ if (ansilove_savefile(&ctx, fileName) == -1) {
+ fprintf(stderr, "\n%s\n", ansilove_error(&ctx));
+ return EXIT_FAILURE;
+ }
/* gather information and report to the command line */
if (fileIsANSi || fileIsBinary ||