Skip to content

Commit 02ae267

Browse files
hawkinspcharris
authored andcommitted
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 f975164 commit 02ae267

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2889,7 +2889,7 @@ OBJECT_nonzero (PyObject **ip, PyArrayObject *ap)
28892889
}
28902890
else {
28912891
PyObject *obj;
2892-
memcpy(&obj, ip, sizeof(obj));
2892+
memcpy(&obj, (void *)ip, sizeof(obj));
28932893
if (obj == NULL) {
28942894
return NPY_FALSE;
28952895
}

0 commit comments

Comments
 (0)