summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_codecs.py9
-rw-r--r--Objects/stringobject.c7
2 files changed, 12 insertions, 4 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 0362d26..36cebd5 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -23,9 +23,16 @@ class UTF16Test(unittest.TestCase):
f = reader(s)
self.assertEquals(f.read(), u"spamspam")
+class EscapeDecodeTest(unittest.TestCase):
+ def test_empty_escape_decode(self):
+ self.assertEquals(codecs.escape_decode(""), ("", 0))
+
def test_main():
- test_support.run_unittest(UTF16Test)
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(UTF16Test))
+ suite.addTest(unittest.makeSuite(EscapeDecodeTest))
+ test_support.run_suite(suite)
if __name__ == "__main__":
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 31f188a..dd38ee3 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -533,8 +533,8 @@ PyObject *PyString_DecodeEscape(const char *s,
char *p, *buf;
const char *end;
PyObject *v;
- v = PyString_FromStringAndSize((char *)NULL,
- recode_encoding ? 4*len:len);
+ int newlen = recode_encoding ? 4*len:len;
+ v = PyString_FromStringAndSize((char *)NULL, newlen);
if (v == NULL)
return NULL;
p = buf = PyString_AsString(v);
@@ -660,7 +660,8 @@ PyObject *PyString_DecodeEscape(const char *s,
break;
}
}
- _PyString_Resize(&v, (int)(p - buf));
+ if (p-buf < newlen)
+ _PyString_Resize(&v, (int)(p - buf));
return v;
failed:
Py_DECREF(v);