summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 00:50:07 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-11-22 00:50:07 (GMT)
commitb84d723509d1b8c7e052f61117624627d334cf30 (patch)
tree24ba2b8446ce3829d9658250da1c4f86dd63c398 /Objects
parentcfed46e00a00380f05917c533a259fe45697a5ec (diff)
downloadcpython-b84d723509d1b8c7e052f61117624627d334cf30.zip
cpython-b84d723509d1b8c7e052f61117624627d334cf30.tar.gz
cpython-b84d723509d1b8c7e052f61117624627d334cf30.tar.bz2
(Merge 3.2) Issue #13093: Fix error handling on PyUnicode_EncodeDecimal()
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 7f079e7..16db801 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8875,22 +8875,25 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
kind = PyUnicode_KIND(unicode);
data = PyUnicode_DATA(unicode);
- for (i=0; i < length; i++) {
+ for (i=0; i < length; ) {
Py_UCS4 ch = PyUnicode_READ(kind, data, i);
int decimal;
Py_ssize_t startpos, endpos;
if (Py_UNICODE_ISSPACE(ch)) {
*output++ = ' ';
+ i++;
continue;
}
decimal = Py_UNICODE_TODECIMAL(ch);
if (decimal >= 0) {
*output++ = '0' + decimal;
+ i++;
continue;
}
if (0 < ch && ch < 256) {
*output++ = (char)ch;
+ i++;
continue;
}
/* All other characters are considered unencodable */
@@ -8899,8 +8902,8 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
for (; endpos < length; endpos++) {
ch = PyUnicode_READ(kind, data, endpos);
if ((0 < ch && ch < 256) ||
- !Py_UNICODE_ISSPACE(ch) ||
- Py_UNICODE_TODECIMAL(ch))
+ Py_UNICODE_ISSPACE(ch) ||
+ 0 <= Py_UNICODE_TODECIMAL(ch))
break;
}
/* cache callback name lookup
@@ -8924,7 +8927,8 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
case 2: /* replace */
for (j=startpos; j < endpos; j++)
*output++ = '?';
- /* fall through */
+ i = endpos;
+ break;
case 3: /* ignore */
i = endpos;
break;