mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-15 03:46:28 +03:00
Merge pull request #3388 from hugovk/andreas-schwab/master
Avoid undefined behaviour due to division by zero
This commit is contained in:
commit
799133b3a4
|
@ -149,10 +149,17 @@ count_used_color_buckets(const ColorCube cube) {
|
||||||
static void
|
static void
|
||||||
avg_color_from_color_bucket(const ColorBucket bucket, Pixel *dst) {
|
avg_color_from_color_bucket(const ColorBucket bucket, Pixel *dst) {
|
||||||
float count = bucket->count;
|
float count = bucket->count;
|
||||||
|
if (count != 0) {
|
||||||
dst->c.r = (int)(bucket->r / count);
|
dst->c.r = (int)(bucket->r / count);
|
||||||
dst->c.g = (int)(bucket->g / count);
|
dst->c.g = (int)(bucket->g / count);
|
||||||
dst->c.b = (int)(bucket->b / count);
|
dst->c.b = (int)(bucket->b / count);
|
||||||
dst->c.a = (int)(bucket->a / count);
|
dst->c.a = (int)(bucket->a / count);
|
||||||
|
} else {
|
||||||
|
dst->c.r = 0;
|
||||||
|
dst->c.g = 0;
|
||||||
|
dst->c.b = 0;
|
||||||
|
dst->c.a = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Reference in New Issue
Block a user