Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
be580f2e
Commit
be580f2e
authored
Apr 25, 2014
by
Kristján Valur Jónsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20434 Correct error handlin of _PyString_Resize and _PyBytes_Resize
parent
4e0df17b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
56 deletions
+32
-56
Modules/_io/fileio.c
Modules/_io/fileio.c
+3
-12
Modules/binascii.c
Modules/binascii.c
+20
-35
Modules/bz2module.c
Modules/bz2module.c
+2
-1
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+2
-4
Objects/stringobject.c
Objects/stringobject.c
+2
-2
PC/_subprocess.c
PC/_subprocess.c
+3
-2
No files found.
Modules/_io/fileio.c
View file @
be580f2e
...
...
@@ -549,14 +549,8 @@ fileio_readall(fileio *self)
}
if
(
PyBytes_GET_SIZE
(
result
)
<
(
Py_ssize_t
)
newsize
)
{
if
(
_PyBytes_Resize
(
&
result
,
newsize
)
<
0
)
{
if
(
total
==
0
)
{
Py_DECREF
(
result
);
return
NULL
;
}
PyErr_Clear
();
break
;
}
if
(
_PyBytes_Resize
(
&
result
,
newsize
)
<
0
)
return
NULL
;
/* result has been freed */
}
Py_BEGIN_ALLOW_THREADS
errno
=
0
;
...
...
@@ -599,7 +593,6 @@ fileio_readall(fileio *self)
if
(
PyBytes_GET_SIZE
(
result
)
>
total
)
{
if
(
_PyBytes_Resize
(
&
result
,
total
)
<
0
)
{
/* This should never happen, but just in case */
Py_DECREF
(
result
);
return
NULL
;
}
}
...
...
@@ -656,10 +649,8 @@ fileio_read(fileio *self, PyObject *args)
}
if
(
n
!=
size
)
{
if
(
_PyBytes_Resize
(
&
bytes
,
n
)
<
0
)
{
Py_DECREF
(
bytes
);
if
(
_PyBytes_Resize
(
&
bytes
,
n
)
<
0
)
return
NULL
;
}
}
return
(
PyObject
*
)
bytes
;
...
...
Modules/binascii.c
View file @
be580f2e
...
...
@@ -320,12 +320,10 @@ binascii_b2a_uu(PyObject *self, PyObject *args)
}
*
ascii_data
++
=
'\n'
;
/* Append a courtesy newline */
if
(
_PyString_Resize
(
&
rv
,
/* rv is cleared on error */
(
void
)
_PyString_Resize
(
&
rv
,
(
ascii_data
-
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)))
<
0
)
{
Py_DECREF
(
rv
);
rv
=
NULL
;
}
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)));
PyBuffer_Release
(
&
pbin
);
return
rv
;
}
...
...
@@ -452,10 +450,8 @@ binascii_a2b_base64(PyObject *self, PyObject *args)
** string instead; _PyString_Resize() won't do this for us.
*/
if
(
bin_len
>
0
)
{
if
(
_PyString_Resize
(
&
rv
,
bin_len
)
<
0
)
{
Py_DECREF
(
rv
);
rv
=
NULL
;
}
/* rv is cleared on error */
(
void
)
_PyString_Resize
(
&
rv
,
bin_len
);
}
else
{
Py_DECREF
(
rv
);
...
...
@@ -522,12 +518,10 @@ binascii_b2a_base64(PyObject *self, PyObject *args)
}
*
ascii_data
++
=
'\n'
;
/* Append a courtesy newline */
if
(
_PyString_Resize
(
&
rv
,
/* rv is cleared on error */
(
void
)
_PyString_Resize
(
&
rv
,
(
ascii_data
-
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)))
<
0
)
{
Py_DECREF
(
rv
);
rv
=
NULL
;
}
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)));
PyBuffer_Release
(
&
pbuf
);
return
rv
;
}
...
...
@@ -601,13 +595,10 @@ binascii_a2b_hqx(PyObject *self, PyObject *args)
Py_DECREF
(
rv
);
return
NULL
;
}
/* rv is cleared on error */
if
(
_PyString_Resize
(
&
rv
,
(
bin_data
-
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)))
<
0
)
{
Py_DECREF
(
rv
);
rv
=
NULL
;
}
if
(
rv
)
{
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)))
==
0
)
{
PyObject
*
rrv
=
Py_BuildValue
(
"Oi"
,
rv
,
done
);
PyBuffer_Release
(
&
pascii
);
Py_DECREF
(
rv
);
...
...
@@ -672,12 +663,10 @@ binascii_rlecode_hqx(PyObject *self, PyObject *args)
}
}
}
if
(
_PyString_Resize
(
&
rv
,
/* rv is cleared on error */
(
void
)
_PyString_Resize
(
&
rv
,
(
out_data
-
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)))
<
0
)
{
Py_DECREF
(
rv
);
rv
=
NULL
;
}
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)));
PyBuffer_Release
(
&
pbuf
);
return
rv
;
}
...
...
@@ -729,12 +718,10 @@ binascii_b2a_hqx(PyObject *self, PyObject *args)
leftchar
<<=
(
6
-
leftbits
);
*
ascii_data
++
=
table_b2a_hqx
[
leftchar
&
0x3f
];
}
if
(
_PyString_Resize
(
&
rv
,
/* rv is cleared on error */
(
void
)
_PyString_Resize
(
&
rv
,
(
ascii_data
-
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)))
<
0
)
{
Py_DECREF
(
rv
);
rv
=
NULL
;
}
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)));
PyBuffer_Release
(
&
pbin
);
return
rv
;
}
...
...
@@ -796,7 +783,7 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
if ( --out_len_left < 0 ) { \
if ( out_len > PY_SSIZE_T_MAX / 2) return PyErr_NoMemory(); \
if (_PyString_Resize(&rv, 2*out_len) < 0) \
{ Py
_DECREF(rv); Py
Buffer_Release(&pin); return NULL; } \
{ PyBuffer_Release(&pin); return NULL; } \
out_data = (unsigned char *)PyString_AS_STRING(rv) \
+ out_len; \
out_len_left = out_len-1; \
...
...
@@ -846,12 +833,10 @@ binascii_rledecode_hqx(PyObject *self, PyObject *args)
OUTBYTE
(
in_byte
);
}
}
if
(
_PyString_Resize
(
&
rv
,
/* rv is cleared on error */
(
void
)
_PyString_Resize
(
&
rv
,
(
out_data
-
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)))
<
0
)
{
Py_DECREF
(
rv
);
rv
=
NULL
;
}
(
unsigned
char
*
)
PyString_AS_STRING
(
rv
)));
PyBuffer_Release
(
&
pin
);
return
rv
;
}
...
...
Modules/bz2module.c
View file @
be580f2e
...
...
@@ -732,7 +732,8 @@ BZ2File_readlines(BZ2FileObject *self, PyObject *args)
}
else
{
/* Grow the big buffer */
_PyString_Resize
(
&
big_buffer
,
buffersize
);
if
(
_PyString_Resize
(
&
big_buffer
,
buffersize
))
goto
error
;
buffer
=
PyString_AS_STRING
(
big_buffer
);
}
continue
;
...
...
Objects/bytearrayobject.c
View file @
be580f2e
...
...
@@ -994,10 +994,8 @@ bytearray_repr(PyByteArrayObject *self)
*
p
++
=
*
quote_postfix
++
;
}
*
p
=
'\0'
;
if
(
_PyString_Resize
(
&
v
,
(
p
-
PyString_AS_STRING
(
v
))))
{
Py_DECREF
(
v
);
return
NULL
;
}
/* v is cleared on error */
(
void
)
_PyString_Resize
(
&
v
,
(
p
-
PyString_AS_STRING
(
v
)));
return
v
;
}
}
...
...
Objects/stringobject.c
View file @
be580f2e
...
...
@@ -748,8 +748,8 @@ PyObject *PyString_DecodeEscape(const char *s,
UTF-8 bytes may follow. */
}
}
if
(
p
-
buf
<
newlen
&&
_PyString_Resize
(
&
v
,
p
-
buf
)
)
goto
failed
;
if
(
p
-
buf
<
newlen
)
_PyString_Resize
(
&
v
,
p
-
buf
);
/* v is cleared on error */
return
v
;
failed:
Py_DECREF
(
v
);
...
...
PC/_subprocess.c
View file @
be580f2e
...
...
@@ -367,7 +367,8 @@ getenvironment(PyObject* environment)
vsize
+
1
+
1
;
if
(
totalsize
>
PyString_GET_SIZE
(
out
))
{
int
offset
=
p
-
PyString_AS_STRING
(
out
);
_PyString_Resize
(
&
out
,
totalsize
+
1024
);
if
(
_PyString_Resize
(
&
out
,
totalsize
+
1024
))
goto
exit
;
p
=
PyString_AS_STRING
(
out
)
+
offset
;
}
memcpy
(
p
,
PyString_AS_STRING
(
key
),
ksize
);
...
...
@@ -383,7 +384,7 @@ getenvironment(PyObject* environment)
_PyString_Resize
(
&
out
,
p
-
PyString_AS_STRING
(
out
));
/* PyObject_Print(out, stdout, 0); */
exit:
Py_XDECREF
(
keys
);
Py_XDECREF
(
values
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment