mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 14:34:33 +02:00
fix some 'unsigned integer overflow' warnings in ubsan
I couldn't find a safe way of fixing VP8GetSigned() so i just used the big-hammer. Change-Id: I1039bc00307d1c90c85909a458a4bc70670e48b7
This commit is contained in:
@ -245,9 +245,9 @@ void VP8LAddGreenToBlueAndRed_C(uint32_t* data, int num_pixels) {
|
||||
}
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t ColorTransformDelta(int8_t color_pred,
|
||||
int8_t color) {
|
||||
return (uint32_t)((int)(color_pred) * color) >> 5;
|
||||
static WEBP_INLINE int ColorTransformDelta(int8_t color_pred,
|
||||
int8_t color) {
|
||||
return ((int)color_pred * color) >> 5;
|
||||
}
|
||||
|
||||
static WEBP_INLINE void ColorCodeToMultipliers(uint32_t color_code,
|
||||
@ -264,8 +264,8 @@ void VP8LTransformColorInverse_C(const VP8LMultipliers* const m, uint32_t* data,
|
||||
const uint32_t argb = data[i];
|
||||
const uint32_t green = argb >> 8;
|
||||
const uint32_t red = argb >> 16;
|
||||
uint32_t new_red = red;
|
||||
uint32_t new_blue = argb;
|
||||
int new_red = red;
|
||||
int new_blue = argb;
|
||||
new_red += ColorTransformDelta(m->green_to_red_, green);
|
||||
new_red &= 0xff;
|
||||
new_blue += ColorTransformDelta(m->green_to_blue_, green);
|
||||
|
@ -342,14 +342,16 @@ static WEBP_INLINE void VP8LPrefixEncode(int distance, int* const code,
|
||||
}
|
||||
|
||||
// Sum of each component, mod 256.
|
||||
static WEBP_INLINE uint32_t VP8LAddPixels(uint32_t a, uint32_t b) {
|
||||
static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW WEBP_INLINE
|
||||
uint32_t VP8LAddPixels(uint32_t a, uint32_t b) {
|
||||
const uint32_t alpha_and_green = (a & 0xff00ff00u) + (b & 0xff00ff00u);
|
||||
const uint32_t red_and_blue = (a & 0x00ff00ffu) + (b & 0x00ff00ffu);
|
||||
return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
|
||||
}
|
||||
|
||||
// Difference of each component, mod 256.
|
||||
static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
|
||||
static WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW WEBP_INLINE
|
||||
uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
|
||||
const uint32_t alpha_and_green =
|
||||
0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u);
|
||||
const uint32_t red_and_blue =
|
||||
|
@ -922,11 +922,11 @@ void VP8LResidualImage(int width, int height, int bits, int low_effort,
|
||||
void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels) {
|
||||
int i;
|
||||
for (i = 0; i < num_pixels; ++i) {
|
||||
const uint32_t argb = argb_data[i];
|
||||
const uint32_t green = (argb >> 8) & 0xff;
|
||||
const int argb = argb_data[i];
|
||||
const int green = (argb >> 8) & 0xff;
|
||||
const uint32_t new_r = (((argb >> 16) & 0xff) - green) & 0xff;
|
||||
const uint32_t new_b = ((argb & 0xff) - green) & 0xff;
|
||||
argb_data[i] = (argb & 0xff00ff00) | (new_r << 16) | new_b;
|
||||
const uint32_t new_b = (((argb >> 0) & 0xff) - green) & 0xff;
|
||||
argb_data[i] = (argb & 0xff00ff00u) | (new_r << 16) | new_b;
|
||||
}
|
||||
}
|
||||
|
||||
@ -936,9 +936,8 @@ static WEBP_INLINE void MultipliersClear(VP8LMultipliers* const m) {
|
||||
m->red_to_blue_ = 0;
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t ColorTransformDelta(int8_t color_pred,
|
||||
int8_t color) {
|
||||
return (uint32_t)((int)(color_pred) * color) >> 5;
|
||||
static WEBP_INLINE int ColorTransformDelta(int8_t color_pred, int8_t color) {
|
||||
return ((int)color_pred * color) >> 5;
|
||||
}
|
||||
|
||||
static WEBP_INLINE void ColorCodeToMultipliers(uint32_t color_code,
|
||||
@ -963,8 +962,8 @@ void VP8LTransformColor_C(const VP8LMultipliers* const m, uint32_t* data,
|
||||
const uint32_t argb = data[i];
|
||||
const uint32_t green = argb >> 8;
|
||||
const uint32_t red = argb >> 16;
|
||||
uint32_t new_red = red;
|
||||
uint32_t new_blue = argb;
|
||||
int new_red = red;
|
||||
int new_blue = argb;
|
||||
new_red -= ColorTransformDelta(m->green_to_red_, green);
|
||||
new_red &= 0xff;
|
||||
new_blue -= ColorTransformDelta(m->green_to_blue_, green);
|
||||
@ -977,7 +976,7 @@ void VP8LTransformColor_C(const VP8LMultipliers* const m, uint32_t* data,
|
||||
static WEBP_INLINE uint8_t TransformColorRed(uint8_t green_to_red,
|
||||
uint32_t argb) {
|
||||
const uint32_t green = argb >> 8;
|
||||
uint32_t new_red = argb >> 16;
|
||||
int new_red = argb >> 16;
|
||||
new_red -= ColorTransformDelta(green_to_red, green);
|
||||
return (new_red & 0xff);
|
||||
}
|
||||
|
Reference in New Issue
Block a user