Mercurial > cpython-lru_cache-weakref
comparison Python/ceval.c @ 39417:74d23cd04421 legacy-trunk
Concatenation on a long string breaks (SF #1526585).
| author | Armin Rigo <arigo@tunes.org> |
|---|---|
| date | Wed, 09 Aug 2006 15:37:26 +0000 |
| parents | a91e739ce333 |
| children | 9a1288d8200f |
comparison
equal
deleted
inserted
replaced
| 39416:0f3ad5b936a8 | 39417:74d23cd04421 |
|---|---|
| 4223 string_concatenate(PyObject *v, PyObject *w, | 4223 string_concatenate(PyObject *v, PyObject *w, |
| 4224 PyFrameObject *f, unsigned char *next_instr) | 4224 PyFrameObject *f, unsigned char *next_instr) |
| 4225 { | 4225 { |
| 4226 /* This function implements 'variable += expr' when both arguments | 4226 /* This function implements 'variable += expr' when both arguments |
| 4227 are strings. */ | 4227 are strings. */ |
| 4228 Py_ssize_t v_len = PyString_GET_SIZE(v); | |
| 4229 Py_ssize_t w_len = PyString_GET_SIZE(w); | |
| 4230 Py_ssize_t new_len = v_len + w_len; | |
| 4231 if (new_len < 0) { | |
| 4232 PyErr_SetString(PyExc_OverflowError, | |
| 4233 "strings are too large to concat"); | |
| 4234 return NULL; | |
| 4235 } | |
| 4228 | 4236 |
| 4229 if (v->ob_refcnt == 2) { | 4237 if (v->ob_refcnt == 2) { |
| 4230 /* In the common case, there are 2 references to the value | 4238 /* In the common case, there are 2 references to the value |
| 4231 * stored in 'variable' when the += is performed: one on the | 4239 * stored in 'variable' when the += is performed: one on the |
| 4232 * value stack (in 'v') and one still stored in the 'variable'. | 4240 * value stack (in 'v') and one still stored in the 'variable'. |
| 4267 | 4275 |
| 4268 if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) { | 4276 if (v->ob_refcnt == 1 && !PyString_CHECK_INTERNED(v)) { |
| 4269 /* Now we own the last reference to 'v', so we can resize it | 4277 /* Now we own the last reference to 'v', so we can resize it |
| 4270 * in-place. | 4278 * in-place. |
| 4271 */ | 4279 */ |
| 4272 Py_ssize_t v_len = PyString_GET_SIZE(v); | 4280 if (_PyString_Resize(&v, new_len) != 0) { |
| 4273 Py_ssize_t w_len = PyString_GET_SIZE(w); | |
| 4274 if (_PyString_Resize(&v, v_len + w_len) != 0) { | |
| 4275 /* XXX if _PyString_Resize() fails, 'v' has been | 4281 /* XXX if _PyString_Resize() fails, 'v' has been |
| 4276 * deallocated so it cannot be put back into 'variable'. | 4282 * deallocated so it cannot be put back into 'variable'. |
| 4277 * The MemoryError is raised when there is no value in | 4283 * The MemoryError is raised when there is no value in |
| 4278 * 'variable', which might (very remotely) be a cause | 4284 * 'variable', which might (very remotely) be a cause |
| 4279 * of incompatibilities. | 4285 * of incompatibilities. |
