libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

commit 5ec4e7536f6e57ccde20977ae695b983f3964b75
parent dd4bb1e9789199c6605b2ac69d7970ba763b3b68
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 18 Oct 2018 16:47:17 +0200

Add error handling for ansilove_init(), ansilove_loadfile() and ansilove_savefile()

Diffstat:
Msrc/init.c | 7+++++++
Msrc/loadfile.c | 7+++++++
Msrc/savefile.c | 6++++++
3 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/init.c b/src/init.c @@ -13,6 +13,13 @@ int ansilove_init(struct ansilove_ctx *ctx, struct ansilove_options *options) { + if (ctx == NULL || options == NULL) { + if (ctx) + ctx->error = ANSILOVE_INVALID_PARAM; + + return -1; + } + memset(ctx, 0, sizeof(*ctx)); memset(options, 0, sizeof(*options)); diff --git a/src/loadfile.c b/src/loadfile.c @@ -20,6 +20,13 @@ ansilove_loadfile(struct ansilove_ctx *ctx, char *input) { int fd; struct stat st; + if (ctx == NULL || input == NULL) { + if (ctx) + ctx->error = ANSILOVE_INVALID_PARAM; + + return -1; + } + // load input file if ((fd = open(input, O_RDONLY)) == -1) { // perror("File error"); diff --git a/src/savefile.c b/src/savefile.c @@ -17,6 +17,12 @@ int ansilove_savefile(struct ansilove_ctx *ctx, char *output) { + if (ctx == NULL || output == NULL) { + if (ctx) + ctx->error = ANSILOVE_INVALID_PARAM; + + return -1; + } FILE *file = fopen(output, "wb");