Changeset - r23194:ea72866c2500
[Not reviewed]
master
0 1 0
Jonathan G Rennison - 7 years ago 2018-01-17 02:34:03
j.g.rennison@gmail.com
Fix: [Blitter] Avoid signed overflow when drawing long lines
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/blitter/common.hpp
Show inline comments
 
@@ -50,11 +50,11 @@ void Blitter::DrawLineGeneric(int x, int
 
		/* compute frac_diff = width * sqrt(dx*dx + dy*dy)
 
		 * Start interval:
 
		 *    max(dx, dy) <= sqrt(dx*dx + dy*dy) <= sqrt(2) * max(dx, dy) <= 3/2 * max(dx, dy) */
 
		int frac_sq = width * width * (dx * dx + dy * dy);
 
		int64 frac_sq = ((int64) width) * ((int64) width) * (((int64) dx) * ((int64) dx) + ((int64) dy) * ((int64) dy));
 
		int frac_max = 3 * frac_diff / 2;
 
		while (frac_diff < frac_max) {
 
			int frac_test = (frac_diff + frac_max) / 2;
 
			if (frac_test * frac_test < frac_sq) {
 
			if (((int64) frac_test) * ((int64) frac_test) < frac_sq) {
 
				frac_diff = frac_test + 1;
 
			} else {
 
				frac_max = frac_test - 1;
0 comments (0 inline, 0 general)