libansilove

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

commit 6a883c62aa7679cb840a347af07ddf4898b32f74
parent acea668e78da1ca217c2a7ebd16f4995c4796fb4
Author: Frederic Cambus <fred@statdns.com>
Date:   Wed, 20 May 2020 20:15:13 +0200

Add error handling for fwrite() in ansilove_savefile().

Diffstat:
Msrc/savefile.c | 7++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/savefile.c b/src/savefile.c @@ -16,6 +16,8 @@ int ansilove_savefile(struct ansilove_ctx *ctx, char *output) { + size_t rw; + if (ctx == NULL || output == NULL) { if (ctx) ctx->error = ANSILOVE_INVALID_PARAM; @@ -28,9 +30,12 @@ ansilove_savefile(struct ansilove_ctx *ctx, char *output) if (!file) goto err; - fwrite(ctx->png.buffer, ctx->png.length, 1, file); + rw = fwrite(ctx->png.buffer, 1, ctx->png.length, file); fclose(file); + if (rw != (size_t)ctx->png.length) + goto err; + return 0; err: