From 33aa5060c25cfb00294638c2c4f6ae4de047d3a7 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Tue, 9 Mar 2021 07:54:37 -0600 Subject: [PATCH] Make sure gradient width is >=2. This should resolve #1070 for real this time. --- src/colours.cc | 4 ++++ src/hsv_gradient.cc | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/colours.cc b/src/colours.cc index 3ffc578d..4437aa46 100644 --- a/src/colours.cc +++ b/src/colours.cc @@ -92,6 +92,10 @@ std::unique_ptr do_gradient(int width, int reddiff, greendiff, bluediff; // difference short redshift = (2 * colour_depth / 3 + colour_depth % 3); short greenshift = (colour_depth / 3); + + // Make sure the width is always at least 2 + width = std::max(2, width); + std::unique_ptr colours(new unsigned long[width]); if (colour_depth == 0) { set_up_gradient(); } diff --git a/src/hsv_gradient.cc b/src/hsv_gradient.cc index 6adc94d4..0962e0c3 100644 --- a/src/hsv_gradient.cc +++ b/src/hsv_gradient.cc @@ -153,6 +153,9 @@ std::unique_ptr do_hsv_gradient(int width, int redshift = (2 * colour_depth / 3 + colour_depth % 3); int greenshift = (colour_depth / 3); + // Make sure the width is always at least 2 + width = std::max(2, width); + std::unique_ptr colours(new unsigned long[width]); if (colour_depth == 0) { set_up_gradient(); }