Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f3dab5

Browse filesBrowse files
committed
Fixed potential overflow exception in the lines.contains() method, if the application happened
to have set the numpy error flags to raise exceptions in case of overflow.
1 parent 2bb91ce commit 6f3dab5
Copy full SHA for 6f3dab5

File tree

Expand file treeCollapse file tree

1 file changed

+16
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-8
lines changed

‎lib/matplotlib/lines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/lines.py
+16-8Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,22 @@ def contains(self, mouseevent):
263263
else:
264264
pixels = self.figure.dpi/72. * self.pickradius
265265

266-
# Check for collision
267-
if self._linestyle in ['None',None]:
268-
# If no line, return the nearby point(s)
269-
d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
270-
ind, = np.nonzero(np.less_equal(d, pixels**2))
271-
else:
272-
# If line, return the nearby segment(s)
273-
ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels)
266+
# the math involved in checking for containment (here and inside of segment_hits) assumes
267+
# that it is OK to overflow. In case the application has set the error flags such that
268+
# an exception is raised on overflow, we temporarily set the appropriate error flags here
269+
# and set them back when we are finished.
270+
olderrflags = np.seterr(all='ignore')
271+
try:
272+
# Check for collision
273+
if self._linestyle in ['None',None]:
274+
# If no line, return the nearby point(s)
275+
d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
276+
ind, = np.nonzero(np.less_equal(d, pixels**2))
277+
else:
278+
# If line, return the nearby segment(s)
279+
ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels)
280+
finally:
281+
np.seterr(**olderrflags)
274282

275283
ind += self.ind_offset
276284

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.