[Python-checkins] r69577 - in python/branches/py3k: Lib/test/test_struct.py Modules/_struct.c

georg.brandl python-checkins at python.org
Fri Feb 13 12:01:07 CET 2009


Author: georg.brandl
Date: Fri Feb 13 12:01:07 2009
New Revision: 69577
Log:
#3694: fix an "XXX undetected error" leak in struct.
Modified:
 python/branches/py3k/Lib/test/test_struct.py
 python/branches/py3k/Modules/_struct.c
Modified: python/branches/py3k/Lib/test/test_struct.py
==============================================================================
--- python/branches/py3k/Lib/test/test_struct.py	(original)
+++ python/branches/py3k/Lib/test/test_struct.py	Fri Feb 13 12:01:07 2009
@@ -524,6 +524,10 @@
 self.assertRaises(struct.error, s.pack_into, small_buf, 0, test_string)
 self.assertRaises(struct.error, s.pack_into, small_buf, 2, test_string)
 
+ # Test bogus offset (issue 3694)
+ sb = small_buf
+ self.assertRaises(TypeError, struct.pack_into, b'1', sb, None)
+
 def test_pack_into_fn(self):
 test_string = b'Reykjavik rocks, eow!'
 writable_buf = array.array('b', b' '*100)
Modified: python/branches/py3k/Modules/_struct.c
==============================================================================
--- python/branches/py3k/Modules/_struct.c	(original)
+++ python/branches/py3k/Modules/_struct.c	Fri Feb 13 12:01:07 2009
@@ -1785,7 +1785,7 @@
 	assert( buffer_len >= 0 );
 
 	/* Extract the offset from the first argument */
-	offset = PyLong_AsSsize_t(PyTuple_GET_ITEM(args, 1));
+	offset = PyNumber_AsSsize_t(PyTuple_GET_ITEM(args, 1), PyExc_IndexError);
 	if (offset == -1 && PyErr_Occurred())
 		return NULL;
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /