summaryrefslogtreecommitdiff
path: root/plugingui/image.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-06-04 21:12:00 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-06-04 21:12:00 +0200
commite43a808290630b4a0810b283ad1e3b9411bb3016 (patch)
treef89c9aa9697fb15a9a6adf8895bcdc93dfbba9f7 /plugingui/image.cc
parent3e747d769f63fde60f6095bd1ae7c651d4237f39 (diff)
Fix crash on image load error.
Diffstat (limited to 'plugingui/image.cc')
-rw-r--r--plugingui/image.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/plugingui/image.cc b/plugingui/image.cc
index a85f752..666170d 100644
--- a/plugingui/image.cc
+++ b/plugingui/image.cc
@@ -95,6 +95,7 @@ void Image::setError()
image_data.clear();
image_data.reserve(_width * _height);
+
for(std::size_t y = 0; y < _height; ++y)
{
for(std::size_t x = 0; x < _width; ++x)
@@ -109,17 +110,25 @@ void Image::setError()
void Image::load(const char* data, size_t size)
{
- unsigned int iw, ih;
+ unsigned int iw{0}, ih{0};
unsigned char* char_image_data{nullptr};
unsigned int res = lodepng_decode32((unsigned char**)&char_image_data,
&iw, &ih,
(const unsigned char*)data, size);
+ if(res != 0)
+ {
+ ERR(image, "Error in lodepng_decode32: %d", res);
+ setError();
+ return;
+ }
+
_width = iw;
_height = ih;
image_data.clear();
image_data.reserve(_width * _height);
+
for(std::size_t y = 0; y < _height; ++y)
{
for(std::size_t x = 0; x < _width; ++x)
@@ -133,13 +142,6 @@ void Image::load(const char* data, size_t size)
assert(image_data.size() == (_width * _height));
std::free(char_image_data);
-
- if(res != 0)
- {
- ERR(image, "Error in lodepng_decode32: %d", res);
- setError();
- return;
- }
}
size_t Image::width() const