From 109143ecd29111fc33e6b431943dc507bf2e32fb Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sat, 21 Dec 2019 18:41:27 +0100 Subject: [PATCH] Save_GOS(): pad with 0's and fix memory leak --- src/cpcformats.c | 25 ++++++++++++++++++------- tests/pic-samples | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/cpcformats.c b/src/cpcformats.c index bdcf9aa0..21cf4644 100644 --- a/src/cpcformats.c +++ b/src/cpcformats.c @@ -853,17 +853,22 @@ void Save_GOS(T_IO_Context* context) context->Height = 168; // Convert the first half // convert and save page 1 - output = raw2crtc(context, 0, 7, &outsize, &r1, 0, 0); file = Open_file_write(context); if (file == NULL) return; + output = raw2crtc(context, 0, 7, &outsize, &r1, 0, 0); File_error = 0; if (!Write_bytes(file, output, outsize)) File_error = 1; // Pad to expected size - // TODO: pad with 0s ? - if (!Write_bytes(file, output, 16384 - outsize)) - File_error = 1; + GFX2_Log(GFX2_DEBUG, "written %lu bytes, padding to 16384\n", outsize); + if (outsize >= 8192) + { + memset(output, 0, 16384 - outsize); + if (!Write_bytes(file, output, 16384 - outsize)) + File_error = 1; + } + free(output); fclose(file); if (File_error) return; @@ -872,19 +877,25 @@ void Save_GOS(T_IO_Context* context) // Advance context to second half of picture context->Target_address += context->Pitch * 168; context->Height = 104; - output = raw2crtc(context, 0, 7, &outsize, &r1, 0, 0); file = Open_file_write_with_alternate_ext(context, "GO2"); if (file == NULL) { File_error = 1; return; } + output = raw2crtc(context, 0, 7, &outsize, &r1, 0, 0); File_error = 0; if (!Write_bytes(file, output, outsize)) File_error = 1; // Pad to expected size - if (!Write_bytes(file, output, 16384 - outsize)) - File_error = 1; + GFX2_Log(GFX2_DEBUG, "written %lu bytes, padding to 16384\n", outsize); + if (outsize >= 8192) + { + memset(output, 0, 16384 - outsize); + if (!Write_bytes(file, output, 16384 - outsize)) + File_error = 1; + } + free(output); fclose(file); if (File_error) return; diff --git a/tests/pic-samples b/tests/pic-samples index 241daff8..4ded3063 160000 --- a/tests/pic-samples +++ b/tests/pic-samples @@ -1 +1 @@ -Subproject commit 241daff8186a0da1a0b01edd02aa64bb68a203c7 +Subproject commit 4ded306347cd1fb72a385daf40537b01705943ef