From 3a547fdeab069901aaee340369b3a3e302e9265a Mon Sep 17 00:00:00 2001 From: Ahmed Alian Date: Wed, 4 Feb 2026 17:38:07 +0200 Subject: [PATCH] Replace static buffer with dynamic allocation in writercwtdata() --- src/lib_ccx/output.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib_ccx/output.c b/src/lib_ccx/output.c index ac9be9257..492c27141 100644 --- a/src/lib_ccx/output.c +++ b/src/lib_ccx/output.c @@ -249,9 +249,22 @@ void writercwtdata(struct lib_cc_decode *ctx, const unsigned char *data, struct LLONG currfts = ctx->timing->fts_now + ctx->timing->fts_global; static uint16_t cbcount = 0; static int cbempty = 0; - static unsigned char cbbuffer[0xFFFF * 3]; // TODO: use malloc + static unsigned char *cbbuffer = NULL; + static int cbbuffer_initialized = 0; static unsigned char cbheader[8 + 2]; + if (!cbbuffer_initialized) + { + cbbuffer = (unsigned char *)malloc(0xFFFF * 3); + if (cbbuffer == NULL) + { + mprint("Error: Failed to allocate memory for cbbuffer\n"); + return; + } + cbbuffer_initialized = 1; + dbg_print(CCX_DMT_VERBOSE, "Allocated RCWT buffer (%d bytes)\n", 0xFFFF * 3); + } + if ((prevfts != currfts && prevfts != -1) || data == NULL || cbcount == 0xFFFF) { // Remove trailing empty or 608 padding caption blocks