]> granicus.if.org Git - python/commitdiff
Fix bug #1301 -- a bad assert in _tkinter.
authorGuido van Rossum <guido@python.org>
Thu, 3 Jan 2008 23:52:04 +0000 (23:52 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 3 Jan 2008 23:52:04 +0000 (23:52 +0000)
Misc/NEWS
Modules/_tkinter.c

index 97027a3cbbd805a269b41b015f5a3791bbb44e3e..67af91e80284bf50fca86152cb7fe30496320922 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -157,6 +157,8 @@ Library
 Extension Modules
 -----------------
 
+- Bug #1301: Bad assert in _tkinter fixed.
+
 - Bug #1649098: Avoid declaration of zero-sized array declaration in
   structure.
 
index 0b853b5b48bc9f29132bec5f7c8ccf9444e4623a..8a702d6daea853a310091b576242814af566cf2a 100644 (file)
@@ -936,10 +936,12 @@ AsObj(PyObject *value)
                /* This #ifdef assumes that Tcl uses UCS-2.
                   See TCL_UTF_MAX test above. */
 #if defined(Py_UNICODE_WIDE) && TCL_UTF_MAX == 3
-               Tcl_UniChar *outbuf;
+               Tcl_UniChar *outbuf = NULL;
                Py_ssize_t i;
-               assert(size < size * sizeof(Tcl_UniChar));
-               outbuf = (Tcl_UniChar*)ckalloc(size * sizeof(Tcl_UniChar));
+               size_t allocsize = ((size_t)size) * sizeof(Tcl_UniChar);
+               if (allocsize >= size)
+                       outbuf = (Tcl_UniChar*)ckalloc(allocsize);
+               /* Else overflow occurred, and we take the next exit */
                if (!outbuf) {
                        PyErr_NoMemory();
                        return NULL;