libansilove

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

commit 1b63b435d03afdc27f99ea3365da5d1e1bc2f033
parent c23a65aed053dd1f30c7e127d3a7e70df92b350c
Author: Frederic Cambus <fred@statdns.com>
Date:   Tue, 29 Sep 2020 17:19:59 +0200

Always check malloc() return value and error out on failed allocations.

Diffstat:
Msrc/loaders/ansi.c | 5+++++
Msrc/loaders/icedraw.c | 5+++++
Msrc/loaders/pcboard.c | 5+++++
3 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -120,6 +120,11 @@ ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) /* ANSi buffer dynamic memory allocation */ ansi_buffer = malloc(ansi_buffer_size * sizeof(struct ansiChar)); + if (ansi_buffer == NULL) { + ctx->error = ANSILOVE_MEMORY_ERROR; + return -1; + } + /* ANSi interpreter */ while (loop < ctx->length) { cursor = &ctx->buffer[loop]; diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c @@ -52,6 +52,11 @@ ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options) uint8_t *ptr, *idf_buffer; idf_buffer = malloc(2); + if (idf_buffer == NULL) { + ctx->error = ANSILOVE_MEMORY_ERROR; + return -1; + } + while (loop < ctx->length - IDF_FONT_LENGTH - IDF_PALETTE_LENGTH) { /* RLE compressed data */ if (ctx->buffer[loop] == 1) { diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c @@ -70,6 +70,11 @@ ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options) /* PCB buffer dynamic memory allocation */ pcboard_buffer = malloc(sizeof (struct pcbChar)); + if (pcboard_buffer == NULL) { + ctx->error = ANSILOVE_MEMORY_ERROR; + return -1; + } + while (loop < ctx->length) { cursor = &ctx->buffer[loop];