From 231ee4dc9da8d85aceb9ef18aa7197dd0023534e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sat, 2 Feb 2013 11:24:43 -0800 Subject: [PATCH] Issue 16398: Add assertions to show why memcmp is safe. --- Modules/_collectionsmodule.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index e0c6f0c9542..17b1ad68e1c 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -425,8 +425,9 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n) else if (n < -halflen) n += len; } - assert(deque->len > 1); + assert((n < len / 2) || (n > len / -2)); + deque->state++; for (i=0 ; ileftindex == 0) { @@ -446,6 +447,8 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n) 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 *));