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 17aad94

Browse filesBrowse files
committed
Fix some theoretical problems with png reading
1 parent 4654a9f commit 17aad94
Copy full SHA for 17aad94

File tree

Expand file treeCollapse file tree

2 files changed

+6
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-6
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,8 @@ def pilread(fname):
12791279
from PIL import Image
12801280
except ImportError:
12811281
return None
1282-
image = Image.open(fname)
1283-
return pil_to_array(image)
1282+
with Image.open(fname) as image:
1283+
return pil_to_array(image)
12841284

12851285
handlers = {'png': _png.read_png, }
12861286
if format is None:

‎src/_png.cpp

Copy file name to clipboardExpand all lines: src/_png.cpp
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ static void _read_png_data(PyObject *py_file_obj, png_bytep data, png_size_t len
328328
Py_ssize_t bufflen;
329329
if (read_method) {
330330
result = PyObject_CallFunction(read_method, (char *)"i", length);
331-
}
332-
if (PyBytes_AsStringAndSize(result, &buffer, &bufflen) == 0) {
333-
if (bufflen == (Py_ssize_t)length) {
334-
memcpy(data, buffer, length);
331+
if (PyBytes_AsStringAndSize(result, &buffer, &bufflen) == 0) {
332+
if (bufflen == (Py_ssize_t)length) {
333+
memcpy(data, buffer, length);
334+
}
335335
}
336336
}
337337
Py_XDECREF(read_method);

0 commit comments

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