From abb5c9fd926b23b8b0644d587c0234222e121c91 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Tue, 25 Jan 2022 11:37:39 +0100 Subject: [PATCH] Fix undefined behavior in line drawing. Left shift of negative values is undefined. --- modules/imgproc/src/drawing.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index 8bbe4fa0e3..65735bd9c3 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -655,7 +655,7 @@ Line2( Mat& img, Point2l pt1, Point2l pt2, const void* color) pt1.y ^= pt2.y & j; x_step = XY_ONE; - y_step = (dy << XY_SHIFT) / (ax | 1); + y_step = dy * (1 << XY_SHIFT) / (ax | 1); ecount = (int)((pt2.x - pt1.x) >> XY_SHIFT); } else @@ -668,7 +668,7 @@ Line2( Mat& img, Point2l pt1, Point2l pt2, const void* color) pt2.y ^= pt1.y & i; pt1.y ^= pt2.y & i; - x_step = (dx << XY_SHIFT) / (ay | 1); + x_step = dx * (1 << XY_SHIFT) / (ay | 1); y_step = XY_ONE; ecount = (int)((pt2.y - pt1.y) >> XY_SHIFT); }