[Python-checkins] cpython: Issue 16398: Add assertions to show why memcmp is safe.

raymond.hettinger python-checkins at python.org
Sat Feb 2 20:24:54 CET 2013


http://hg.python.org/cpython/rev/efb8d80af320
changeset:   81944:efb8d80af320
parent:      81941:f7b01daffe01
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Feb 02 11:24:43 2013 -0800
summary:
  Issue 16398:  Add assertions to show why memcmp is safe.

files:
  Modules/_collectionsmodule.c |  5 ++++-
  1 files changed, 4 insertions(+), 1 deletions(-)


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -425,8 +425,9 @@
         else if (n < -halflen)
             n += len;
     }
+    assert(deque->len > 1);
+    assert((n < len / 2) || (n > len / -2));
 
-    assert(deque->len > 1);
     deque->state++;
     for (i=0 ; i<n ; ) {
         if (deque->leftindex == 0) {
@@ -446,6 +447,8 @@
         if (m > deque->leftindex)
             m = deque->leftindex;
         assert (m > 0);
+        assert (deque->leftblock != deque->rightblock ||
+                deque->leftindex < deque->rightindex - m + 1);
         memcpy(&deque->leftblock->data[deque->leftindex - m],
                &deque->rightblock->data[deque->rightindex - m + 1],
                m * sizeof(PyObject *));

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list