8000 Fix some theoretical problems with png reading · matplotlib/matplotlib@17aad94 · GitHub
[go: up one dir, main page]

Skip to content

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 files
committed
Fix some theoretical problems with png reading
1 parent 4654a9f commit 17aad94

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/matplotlib/image.py

Lines 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

Lines 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