diff --git a/src/common/textures/m_png.cpp b/src/common/textures/m_png.cpp index 331b35e200e..83714a6ac2c 100644 --- a/src/common/textures/m_png.cpp +++ b/src/common/textures/m_png.cpp @@ -54,7 +54,7 @@ // MACROS ------------------------------------------------------------------ // The maximum size of an IDAT chunk ZDoom will write. This is also the -// size of the compression buffer it allocates on the stack. +// size of the compression buffer it allocates on the heap. #define PNG_WRITE_SIZE 32768 // Set this to 1 to use a simple heuristic to select the filter to apply @@ -926,8 +926,7 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height temprow[i] = &temprow_storage[temprow_size * i]; } - TArray array(PNG_WRITE_SIZE, true); - auto buffer = array.data(); + TArray buffer(PNG_WRITE_SIZE, true); z_stream stream; int err; int y; @@ -944,8 +943,8 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height } y = height; - stream.next_out = buffer; - stream.avail_out = sizeof(buffer); + stream.next_out = buffer.data(); + stream.avail_out = buffer.size(); temprow[0][0] = 0; #if USE_FILTER_HEURISTIC @@ -1007,12 +1006,12 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height } while (stream.avail_out == 0) { - if (!WriteIDAT (file, buffer, sizeof(buffer))) + if (!WriteIDAT (file, buffer.data(), buffer.size())) { return false; } - stream.next_out = buffer; - stream.avail_out = sizeof(buffer); + stream.next_out = buffer.data(); + stream.avail_out = buffer.size(); if (stream.avail_in != 0) { err = deflate (&stream, (y == 0) ? Z_FINISH : 0); @@ -1033,12 +1032,12 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height } if (stream.avail_out == 0) { - if (!WriteIDAT (file, buffer, sizeof(buffer))) + if (!WriteIDAT (file, buffer.data(), buffer.size())) { return false; } - stream.next_out = buffer; - stream.avail_out = sizeof(buffer); + stream.next_out = buffer.data(); + stream.avail_out = buffer.size(); } } @@ -1048,7 +1047,7 @@ bool M_SaveBitmap(const uint8_t *from, ESSType color_type, int width, int height { return false; } - return WriteIDAT (file, buffer, sizeof(buffer)-stream.avail_out); + return WriteIDAT (file, buffer.data(), buffer.size() - stream.avail_out); } //==========================================================================