Skip to content

Commit fa21c58

Browse files
committed
Fix -fsanitize=alignment issue in numpy/_core/src/multiarray/arraytypes.c.src
OBJECT_nonzero may be called with misaligned pointers, manifesting as a -fsanitize=alignment failure. This is UB per C11 6.3.2.3 > A pointer to an object type may be converted to a pointer to a different object type. If the resulting pointer is not correctly aligned) for the referenced type, the behavior is undefined. Nevertheless, Clang only checks alignment when the unaligned pointer is accessed. https://lists.llvm.org/pipermail/llvm-dev/2016-January/094012.html Call memcpy with unaligned arguments instead to work with new Clang (llvm/llvm-project#67766).
1 parent 676534c commit fa21c58

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

numpy/_core/src/multiarray/arraytypes.c.src

+1-1
Original file line numberDiff line numberDiff line change
@@ -2856,7 +2856,7 @@ OBJECT_nonzero (PyObject **ip, PyArrayObject *ap)
28562856
}
28572857
else {
28582858
PyObject *obj;
2859-
memcpy(&obj, ip, sizeof(obj));
2859+
memcpy(&obj, (void *)ip, sizeof(obj));
28602860
if (obj == NULL) {
28612861
return NPY_FALSE;
28622862
}

0 commit comments

Comments
 (0)