commit 4bf7afb8c907822d2f58d64503c410b90f302566
parent 770b91cc0313e0aad126774acced198e2507d67e
Author: Frederic Cambus <fred@statdns.com>
Date: Wed, 31 Oct 2018 22:18:28 +0100
Add error handling for realloc, and get rid of temp
Diffstat:
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c
@@ -53,7 +53,7 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
uint32_t column = 0, row = 0, columnMax = 0, rowMax = 0;
// PCB buffer structure array definition
- struct pcbChar *pcboard_buffer, *temp;
+ struct pcbChar *pcboard_buffer;
// PCB buffer dynamic memory allocation
pcboard_buffer = malloc(sizeof (struct pcbChar));
@@ -131,8 +131,13 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
rowMax = row;
// reallocate structure array memory
- temp = realloc(pcboard_buffer, (structIndex + 1) * sizeof (struct pcbChar));
- pcboard_buffer = temp;
+ pcboard_buffer = realloc(pcboard_buffer, (structIndex + 1) * sizeof (struct pcbChar));
+ if (pcboard_buffer == NULL) {
+ ctx->error = ANSILOVE_MEMORY_ERROR;
+ free(pcboard_buffer);
+ pcboard_buffer = NULL;
+ return -1;
+ }
// write current character in pcbChar structure
pcboard_buffer[structIndex].column = column;