Commit f06062f5 authored by Anton Mitrofanov's avatar Anton Mitrofanov
Browse files

Fix integer overflow detected by UBSan in --weightp analysis

Bug report by Xuezhi Yan.
parent 3147fa43
...@@ -405,8 +405,7 @@ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int ...@@ -405,8 +405,7 @@ void x264_weights_analyse( x264_t *h, x264_frame_t *fenc, x264_frame_t *ref, int
* because scale has a much wider range than offset (because of denom), so * because scale has a much wider range than offset (because of denom), so
* it should almost never need to be clamped. */ * it should almost never need to be clamped. */
cur_offset = x264_clip3( cur_offset, -128, 127 ); cur_offset = x264_clip3( cur_offset, -128, 127 );
cur_scale = (1 << mindenom) * (fenc_mean[plane] - cur_offset) / ref_mean[plane] + 0.5f; cur_scale = x264_clip3f( (1 << mindenom) * (fenc_mean[plane] - cur_offset) / ref_mean[plane] + 0.5f, 0, 127 );
cur_scale = x264_clip3( cur_scale, 0, 127 );
} }
int start_offset = x264_clip3( cur_offset - offset_dist, -128, 127 ); int start_offset = x264_clip3( cur_offset - offset_dist, -128, 127 );
int end_offset = x264_clip3( cur_offset + offset_dist, -128, 127 ); int end_offset = x264_clip3( cur_offset + offset_dist, -128, 127 );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment