summaryrefslogtreecommitdiff
path: root/numpy/random
diff options
context:
space:
mode:
authorYu Feng <rainwoodman@gmail.com>2017-04-10 10:38:58 -0700
committerYu Feng <rainwoodman@gmail.com>2017-04-10 10:38:58 -0700
commit44f2a623e177606a2d5c27b7b26d5d8d3af8a0da (patch)
tree7b6c14f066a597b1c9e4efc5ddc30b8c2fbb9980 /numpy/random
parent32776774fd6d7f0e62e68ff191b8f834a77932a4 (diff)
downloadpython-numpy-44f2a623e177606a2d5c27b7b26d5d8d3af8a0da.tar.gz
python-numpy-44f2a623e177606a2d5c27b7b26d5d8d3af8a0da.tar.bz2
python-numpy-44f2a623e177606a2d5c27b7b26d5d8d3af8a0da.zip
MAINT: avoid memcpy when i == j
Valgrind complains about memcpy with overlapping address in mtrand.c It happens when i == j in this loop. Closer inspection the i == j iteration is not needed (it is a swap). So, skip it and avoid depending on undefined behavior of memcpy. related read: https://sourceware.org/bugzilla/show_bug.cgi?id=12518
Diffstat (limited to 'numpy/random')
-rw-r--r--numpy/random/mtrand/mtrand.pyx1
1 files changed, 1 insertions, 0 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index bf3a385a9..ee5749d14 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -4828,6 +4828,7 @@ cdef class RandomState:
cdef npy_intp i, j
for i in reversed(range(1, n)):
j = rk_interval(i, self.internal_state)
+ if i == j : continue # i == j is not needed and memcpy is undefined.
string.memcpy(buf, data + j * stride, itemsize)
string.memcpy(data + j * stride, data + i * stride, itemsize)
string.memcpy(data + i * stride, buf, itemsize)