summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-04-18 00:16:52 +0200
committerwm4 <wm4@nowhere>2020-04-18 00:16:52 +0200
commita09c7691d7ecaf49666d16f5276b9e7a14197c37 (patch)
treee8668ac1e1edd0c5932f831b74a4381d834bc326
parentab201ce04235e61534b1070cc49ea455a8296e26 (diff)
downloadmpv-a09c7691d7ecaf49666d16f5276b9e7a14197c37.tar.bz2
mpv-a09c7691d7ecaf49666d16f5276b9e7a14197c37.tar.xz
draw_bmp: silence another ridiculous ubsan warning
UB sanitizer complains that aval<<24 (if >=128) cannot be represented as int. Indeed, we would shift a bit into the sign of an int, which is probably UB or implementation defined (I can't even remember, but the stupidity of it burns). So technically, ubsan might be right. Change aval to uint32_t, which I don't think has a chance of getting promoted to int. Change the other *val to uint32_t too for cosmetic symmetry. So we have to obscure the intention of the code (*val can take only 8 bits) out of language stupidity. How nice. (What a shitty language.)
-rw-r--r--sub/draw_bmp.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c
index a4847b1534..0c913c86fd 100644
--- a/sub/draw_bmp.c
+++ b/sub/draw_bmp.c
@@ -148,10 +148,10 @@ static void unpremultiply_and_split_BGR32(struct mp_image *img,
uint8_t *arow = &alpha->planes[0][alpha->stride[0] * y];
for (int x = 0; x < img->w; ++x) {
uint32_t pval = irow[x];
- uint8_t aval = (pval >> 24);
- uint8_t rval = (pval >> 16) & 0xFF;
- uint8_t gval = (pval >> 8) & 0xFF;
- uint8_t bval = pval & 0xFF;
+ uint32_t aval = (pval >> 24);
+ uint32_t rval = (pval >> 16) & 0xFF;
+ uint32_t gval = (pval >> 8) & 0xFF;
+ uint32_t bval = pval & 0xFF;
// multiplied = separate * alpha / 255
// separate = rint(multiplied * 255 / alpha)
// = floor(multiplied * 255 / alpha + 0.5)