]> granicus.if.org Git - python/commitdiff
Issue #532631: Apply floatformat changes to unicodeobject.c
authorMark Dickinson <dickinsm@gmail.com>
Sun, 29 Mar 2009 16:24:29 +0000 (16:24 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 29 Mar 2009 16:24:29 +0000 (16:24 +0000)
as well as stringobject.c.

Objects/unicodeobject.c

index 4ce9bed1894a58725b70fd1e29b0d542a0826031..6edc2f8347c2a7f6e8dc39d671b4902246fb5453 100644 (file)
@@ -8286,6 +8286,15 @@ formatfloat(Py_UNICODE *buf,
         return -1;
     if (prec < 0)
         prec = 6;
+    /* make sure that the decimal representation of precision really does
+       need at most 10 digits: platforms with sizeof(int) == 8 exist! */
+    if (prec > 0x7fffffffL) {
+        PyErr_SetString(PyExc_OverflowError,
+                        "outrageously large precision "
+                        "for formatted float");
+        return -1;
+    }
+
     if (type == 'f' && fabs(x) >= 1e50)
         type = 'g';
     /* Worst case length calc to ensure no buffer overrun: