diff options
author | Frank Plowman <post@frankplowman.com> | 2024-01-20 14:51:04 +0000 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-01-23 11:17:05 -0300 |
commit | 8157b5d4051d52d9bcabda9dcd5f012d070cba71 (patch) | |
tree | 1e49de45254653b56b232e1807a6527495a89177 /libavcodec/vvc/vvc_inter.c | |
parent | 2d712314ecb64e562243986401522d2c8ffc00cc (diff) | |
download | ffmpeg-8157b5d4051d52d9bcabda9dcd5f012d070cba71.tar.gz |
lavc/vvc: Remove left shifts of negative values
VVC specifies << as arithmetic left shift, i.e. x << y is equivalent to
x * pow2(y). C's << on the other hand has UB if x is negative. This
patch removes all UB resulting from this, mostly by replacing x << y
with x * (1 << y), but there are also a couple places where the OOP was
changed instead.
Signed-off-by: Frank Plowman <post@frankplowman.com>
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/vvc/vvc_inter.c')
-rw-r--r-- | libavcodec/vvc/vvc_inter.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/libavcodec/vvc/vvc_inter.c b/libavcodec/vvc/vvc_inter.c index 9b2925f60c..e05f3db93e 100644 --- a/libavcodec/vvc/vvc_inter.c +++ b/libavcodec/vvc/vvc_inter.c @@ -190,7 +190,7 @@ static void luma_mc(VVCLocalContext *lc, int16_t *dst, const AVFrame *ref, const x_off += mv->x >> 4; y_off += mv->y >> 4; - src += y_off * src_stride + (x_off << fc->ps.sps->pixel_shift); + src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); @@ -213,7 +213,7 @@ static void chroma_mc(VVCLocalContext *lc, int16_t *dst, const AVFrame *ref, con x_off += mv->x >> (4 + hs); y_off += mv->y >> (4 + vs); - src += y_off * src_stride + (x_off << fc->ps.sps->pixel_shift); + src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); EMULATED_EDGE_CHROMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); fc->vvcdsp.inter.put[CHROMA][idx][!!my][!!mx](dst, src, src_stride, block_h, hf, vf, block_w); @@ -237,7 +237,7 @@ static void luma_mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_s x_off += mv->x >> 4; y_off += mv->y >> 4; - src += y_off * src_stride + (x_off << fc->ps.sps->pixel_shift); + src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); @@ -270,7 +270,7 @@ static void luma_mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_st const int ox = x_off + (mv->x >> 4); const int oy = y_off + (mv->y >> 4); ptrdiff_t src_stride = ref[i]->linesize[0]; - const uint8_t *src = ref[i]->data[0] + oy * src_stride + (ox << fc->ps.sps->pixel_shift); + const uint8_t *src = ref[i]->data[0] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift)); const int8_t *hf = ff_vvc_inter_luma_filters[hf_idx][mx]; const int8_t *vf = ff_vvc_inter_luma_filters[vf_idx][my]; @@ -314,7 +314,7 @@ static void chroma_mc_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst x_off += mv->x >> (4 + hs); y_off += mv->y >> (4 + vs); - src += y_off * src_stride + (x_off << fc->ps.sps->pixel_shift); + src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); EMULATED_EDGE_CHROMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); @@ -348,7 +348,7 @@ static void chroma_mc_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_ const int ox = x_off + (mv->x >> (4 + hs)); const int oy = y_off + (mv->y >> (4 + vs)); ptrdiff_t src_stride = ref[i]->linesize[c_idx]; - const uint8_t *src = ref[i]->data[c_idx] + oy * src_stride + (ox << fc->ps.sps->pixel_shift); + const uint8_t *src = ref[i]->data[c_idx] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift)); const int8_t *hf = ff_vvc_inter_chroma_filters[hf_idx][mx]; const int8_t *vf = ff_vvc_inter_chroma_filters[vf_idx][my]; if (dmvr_flag) { @@ -386,7 +386,7 @@ static void luma_prof_uni(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst x_off += mv->x >> 4; y_off += mv->y >> 4; - src += y_off * src_stride + (x_off << fc->ps.sps->pixel_shift); + src += y_off * src_stride + (x_off * (1 << fc->ps.sps->pixel_shift)); EMULATED_EDGE_LUMA(lc->edge_emu_buffer, &src, &src_stride, x_off, y_off); if (cb_prof_flag) { @@ -424,7 +424,7 @@ static void luma_prof_bi(VVCLocalContext *lc, uint8_t *dst, const ptrdiff_t dst_ const int ox = x_off + (mv->x >> 4); const int oy = y_off + (mv->y >> 4); ptrdiff_t src_stride = ref[i]->linesize[0]; - const uint8_t *src = ref[i]->data[0] + oy * src_stride + (ox << fc->ps.sps->pixel_shift); + const uint8_t *src = ref[i]->data[0] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift)); const int8_t *hf = ff_vvc_inter_luma_filters[2][mx]; const int8_t *vf = ff_vvc_inter_luma_filters[2][my]; @@ -654,7 +654,7 @@ static int parametric_mv_refine(const int *sad, const int stride) else if (sad_plus == sad_center) dmvc = 8; else { - int num = ( sad_minus - sad_plus ) << 4; + int num = ( sad_minus - sad_plus ) * (1 << 4); int sign_num = 0; int quotient = 0; int counter = 3; @@ -704,7 +704,7 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, const int ox = x_off + (mv->x >> 4) - sr_range; const int oy = y_off + (mv->y >> 4) - sr_range; ptrdiff_t src_stride = ref[i]->linesize[LUMA]; - const uint8_t *src = ref[i]->data[LUMA] + oy * src_stride + (ox << fc->ps.sps->pixel_shift); + const uint8_t *src = ref[i]->data[LUMA] + oy * src_stride + (ox * (1 << fc->ps.sps->pixel_shift)); EMULATED_EDGE_BILINEAR(lc->edge_emu_buffer, &src, &src_stride, ox, oy); fc->vvcdsp.inter.dmvr[!!my][!!mx](tmp[i], src, src_stride, pred_h, mx, my, pred_w); } @@ -728,8 +728,8 @@ static void dmvr_mv_refine(VVCLocalContext *lc, MvField *mvf, MvField *orig_mv, } } } - dmv[0] = (min_dx - sr_range) << 4; - dmv[1] = (min_dy - sr_range) << 4; + dmv[0] = (min_dx - sr_range) * (1 << 4); + dmv[1] = (min_dy - sr_range) * (1 << 4); if (min_dx != 0 && min_dx != 4 && min_dy != 0 && min_dy != 4) { dmv[0] += parametric_mv_refine(&sad[min_dy][min_dx], 1); dmv[1] += parametric_mv_refine(&sad[min_dy][min_dx], SAD_ARRAY_SIZE); |