Merge pull request #4653 from radarhere/clip

Corrected undefined behaviour
This commit is contained in:
Hugo van Kemenade 2020-06-20 15:57:30 +03:00 committed by GitHub
commit dbadd2d39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,6 +28,7 @@
#include <string.h>
#include <limits.h>
#include "ImagingUtils.h"
#include "QuantOctree.h"
typedef struct _ColorBucket{
@ -152,10 +153,10 @@ static void
avg_color_from_color_bucket(const ColorBucket bucket, Pixel *dst) {
float count = bucket->count;
if (count != 0) {
dst->c.r = (int)(bucket->r / count);
dst->c.g = (int)(bucket->g / count);
dst->c.b = (int)(bucket->b / count);
dst->c.a = (int)(bucket->a / count);
dst->c.r = CLIP8((int)(bucket->r / count));
dst->c.g = CLIP8((int)(bucket->g / count));
dst->c.b = CLIP8((int)(bucket->b / count));
dst->c.a = CLIP8((int)(bucket->a / count));
} else {
dst->c.r = 0;
dst->c.g = 0;