From 7b52dc232410c422a08fb59a8577f9829d7cf2b3 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 22 Feb 2021 19:43:04 +0100 Subject: [PATCH] Fixing build on gcc/clang --- src/libslic3r/PNGReadWrite.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/PNGReadWrite.cpp b/src/libslic3r/PNGReadWrite.cpp index f04ccd6ef..3308f1fd4 100644 --- a/src/libslic3r/PNGReadWrite.cpp +++ b/src/libslic3r/PNGReadWrite.cpp @@ -149,13 +149,15 @@ static bool write_rgb_or_gray_to_file(const char *file_name_utf8, size_t width, // Initialize rows of PNG. row_pointers = reinterpret_cast(::png_malloc(png_ptr, height * sizeof(png_byte*))); - int line_width = width; - if (png_color_type == PNG_COLOR_TYPE_RGB) - line_width *= 3; - for (size_t y = 0; y < height; ++ y) { - auto row = reinterpret_cast(::png_malloc(png_ptr, line_width)); - row_pointers[y] = row; - memcpy(row, data + line_width * y, line_width); + { + int line_width = width; + if (png_color_type == PNG_COLOR_TYPE_RGB) + line_width *= 3; + for (size_t y = 0; y < height; ++ y) { + auto row = reinterpret_cast(::png_malloc(png_ptr, line_width)); + row_pointers[y] = row; + memcpy(row, data + line_width * y, line_width); + } } // Write the image data to "fp".