commit b3ac541e3557b1d5fc03c3502493559ce1fe3505
parent 4bf7afb8c907822d2f58d64503c410b90f302566
Author: Frederic Cambus <fred@statdns.com>
Date: Wed, 31 Oct 2018 22:21:58 +0100
Better error handling for realloc, and get rid of temp in the IDF loader
Diffstat:
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c
@@ -48,7 +48,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
uint32_t idf_sequence_length, idf_sequence_loop, i = 0;
// dynamically allocated memory buffer for IDF data
- unsigned char *idf_buffer, *temp;
+ unsigned char *idf_buffer;
idf_buffer = malloc(2);
uint16_t idf_data, idf_data_length;
@@ -65,10 +65,8 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
for (idf_sequence_loop = 0; idf_sequence_loop < idf_sequence_length; idf_sequence_loop++)
{
// reallocate IDF buffer memory
- temp = realloc(idf_buffer, i + 2);
- if (idf_buffer != NULL) {
- idf_buffer = temp;
- } else {
+ idf_buffer = realloc(idf_buffer, i + 2);
+ if (idf_buffer == NULL) {
ctx->error = ANSILOVE_MEMORY_ERROR;
free(idf_buffer);
idf_buffer = NULL;
@@ -82,11 +80,11 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options)
loop += 4;
} else {
// reallocate IDF buffer memory
- temp = realloc(idf_buffer, i + 2);
- if (idf_buffer != NULL) {
- idf_buffer = temp;
- } else {
+ idf_buffer = realloc(idf_buffer, i + 2);
+ if (idf_buffer == NULL) {
ctx->error = ANSILOVE_MEMORY_ERROR;
+ free(idf_buffer);
+ idf_buffer = NULL;
return -1;
}