summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2022-05-11 16:12:31 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2022-05-11 17:39:27 +0800
commit34c1a2beaa8ae92a445b85458d3681f60cd5216f (patch)
treebe0a89764b4312bed70984cbdf3a216db46b8d62 /core
parent1eebf0d789f44870a32a1b36a6609a19647a836f (diff)
Fix invalid memory usage when using Image.convert
Diffstat (limited to 'core')
-rw-r--r--core/io/image.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp
index 661a9f7177..671a000e2c 100644
--- a/core/io/image.cpp
+++ b/core/io/image.cpp
@@ -436,7 +436,7 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
const uint8_t *rofs = &p_src[((y * p_width) + x) * (read_bytes + (read_alpha ? 1 : 0))];
uint8_t *wofs = &p_dst[((y * p_width) + x) * (write_bytes + (write_alpha ? 1 : 0))];
- uint8_t rgba[4];
+ uint8_t rgba[4] = { 0, 0, 0, 255 };
if (read_gray) {
rgba[0] = rofs[0];
@@ -454,7 +454,7 @@ static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p
if (write_gray) {
//TODO: not correct grayscale, should use fixed point version of actual weights
- wofs[0] = uint8_t((uint16_t(rofs[0]) + uint16_t(rofs[1]) + uint16_t(rofs[2])) / 3);
+ wofs[0] = uint8_t((uint16_t(rgba[0]) + uint16_t(rgba[1]) + uint16_t(rgba[2])) / 3);
} else {
for (uint32_t i = 0; i < write_bytes; i++) {
wofs[i] = rgba[i];