summaryrefslogtreecommitdiffstats
path: root/Modules/binascii.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-10-14 13:02:35 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-10-14 13:02:35 (GMT)
commit1bfe9305859cf280464ed1f40fc9e2793b0f03b7 (patch)
tree0263e5bdceb6457ed61bbbde654f8845cd0553f0 /Modules/binascii.c
parentc3d2bc19e47892e19c9ad6a048047964dbb78cb6 (diff)
downloadcpython-1bfe9305859cf280464ed1f40fc9e2793b0f03b7.zip
cpython-1bfe9305859cf280464ed1f40fc9e2793b0f03b7.tar.gz
cpython-1bfe9305859cf280464ed1f40fc9e2793b0f03b7.tar.bz2
Issue #25384: Fix binascii.rledecode_hqx()
Fix usage of _PyBytesWriter API. Use the new _PyBytesWriter_Resize() function instead of _PyBytesWriter_Prepare().
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r--Modules/binascii.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c
index dfa5535..a1070b7 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -800,14 +800,15 @@ binascii_rledecode_hqx_impl(PyModuleDef *module, Py_buffer *data)
return PyErr_NoMemory();
/* Allocate a buffer of reasonable size. Resized when needed */
- out_len = in_len * 2;
+ out_len = in_len;
out_data = _PyBytesWriter_Alloc(&writer, out_len);
if (out_data == NULL)
return NULL;
/* Use overallocation */
writer.overallocate = 1;
- out_len_left = writer.allocated;
+ out_len = writer.allocated;
+ out_len_left = out_len;
/*
** We need two macros here to get/put bytes and handle
@@ -830,10 +831,12 @@ binascii_rledecode_hqx_impl(PyModuleDef *module, Py_buffer *data)
overallocate the buffer anymore */ \
writer.overallocate = 0; \
} \
- out_data = _PyBytesWriter_Prepare(&writer, out_data, 1); \
+ out_data = _PyBytesWriter_Resize(&writer, out_data, \
+ writer.allocated + 1); \
if (out_data == NULL) \
goto error; \
- out_len_left = writer.allocated; \
+ out_len_left = writer.allocated - out_len - 1; \
+ out_len = writer.allocated; \
} \
*out_data++ = b; \
} while(0)