8000 Agg: Fix overflow when splitting large lines · matplotlib/matplotlib@474bb4f · GitHub
[go: up one dir, main page]

Skip to content

Commit 474bb4f

Browse files
committed
Agg: Fix overflow when splitting large lines
For very large Figures with a single Axes, the horizontal spines may be long enough to need splitting into separate lines. For large enough coordinates, the `x1+x2` calculation may overflow, flipping the sign bit, causing the coordinates to become negative. This causes an infinite loop as some internal condition is never met. By dividing `x1`/`x2` by 2 first, we avoid the overflow, and can calculate the split point correctly.
1 parent 7d73e2a commit 474bb4f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

extern/agg24-svn/include/agg_rasterizer_cells_aa.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,10 @@ namespace agg
325325

326326
if(dx >= dx_limit || dx <= -dx_limit)
327327
{
328-
int cx = (x1 + x2) >> 1;
329-
int cy = (y1 + y2) >> 1;
328+
// These are overflow safe versions of (x1 + x2) >> 1; divide each by 2
329+
// first, then add 1 if both were odd.
330+
int cx = (x1 >> 1) + (x2 >> 1) + ((x1 & 1) & (x2 & 1));
331+
int cy = (y1 >> 1) + (y2 >> 1) + ((y1 & 1) & (y2 & 1));
330332
line(x1, y1, cx, cy);
331333
line(cx, cy, x2, y2);
332334
return;

0 commit comments

Comments
 (0)
0