From 5d5aafae37bb456ccaaf78897eb78003fdac5d48 Mon Sep 17 00:00:00 2001 From: Gregor Weiss Date: Tue, 5 Nov 2024 11:12:12 +0100 Subject: [PATCH] bug fixes in bwc_set_aux and bwc_set_com, both missing allocation of bwc_span --- src/library/libbwc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/library/libbwc.c b/src/library/libbwc.c index 0beb985..b886f64 100755 --- a/src/library/libbwc.c +++ b/src/library/libbwc.c @@ -1498,8 +1498,9 @@ bwc_set_com(bwc_stream *const data, char const *const com, uint16 size) ! Save the global info structure to a temporary variable ! ! to make the code more readable. ! \*--------------------------------------------------------*/ + data->codestream.com = calloc(1, sizeof(bwc_span)); data->codestream.com->memory = calloc(size, sizeof(char)); - if(!data->codestream.com->memory) + if(!data->codestream.com->memory) { // memory allocation error fprintf(stderr, MEMERROR); @@ -1536,18 +1537,19 @@ bwc_set_aux(bwc_stream *const data, char const *const aux, uint32 size) ! Save the global info structure to a temporary variable ! ! to make the code more readable. ! \*--------------------------------------------------------*/ - data->codestream.com->memory = calloc(size, sizeof(char)); - if(!data->codestream.com->memory) + data->codestream.aux = calloc(1, sizeof(bwc_span)); + data->codestream.aux->memory = calloc(size, sizeof(char)); + if(!data->codestream.aux->memory) { // memory allocation error fprintf(stderr, MEMERROR); return 1; } - memcpy(data->codestream.com->memory, aux, size * sizeof(char)); - data->codestream.com->access = data->codestream.com->memory; - data->codestream.com->size = size; - data->codestream.com->position = 0; + memcpy(data->codestream.aux->memory, aux, size * sizeof(char)); + data->codestream.aux->access = data->codestream.aux->memory; + data->codestream.aux->size = size; + data->codestream.aux->position = 0; return 0; }