diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-08-14 00:22:18 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-08-14 00:22:18 (GMT) |
commit | 7bc44302a0826d68073aefa7522ac7871959e949 (patch) | |
tree | 7e7fab3ee682fb2be820a4c1849fa1e7f56fc379 /Modules/_csv.c | |
parent | c00189e94995aab6d5d06d3914baadea550fa138 (diff) | |
parent | 9745ee0b444c92a23a1b8851f789044baa64dba5 (diff) | |
download | cpython-7bc44302a0826d68073aefa7522ac7871959e949.zip cpython-7bc44302a0826d68073aefa7522ac7871959e949.tar.gz cpython-7bc44302a0826d68073aefa7522ac7871959e949.tar.bz2 |
merge 3.5 (closes #27758)
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r-- | Modules/_csv.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c index 4284477..ef2e7d7 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -1014,11 +1014,19 @@ join_append_data(WriterObj *self, unsigned int field_kind, void *field_data, int i; Py_ssize_t rec_len; -#define ADDCH(c) \ +#define INCLEN \ + do {\ + if (!copy_phase && rec_len == PY_SSIZE_T_MAX) { \ + goto overflow; \ + } \ + rec_len++; \ + } while(0) + +#define ADDCH(c) \ do {\ if (copy_phase) \ self->rec[rec_len] = c;\ - rec_len++;\ + INCLEN;\ } while(0) rec_len = self->rec_len; @@ -1072,11 +1080,18 @@ join_append_data(WriterObj *self, unsigned int field_kind, void *field_data, if (*quoted) { if (copy_phase) ADDCH(dialect->quotechar); - else - rec_len += 2; + else { + INCLEN; /* starting quote */ + INCLEN; /* ending quote */ + } } return rec_len; + + overflow: + PyErr_NoMemory(); + return -1; #undef ADDCH +#undef INCLEN } static int |