Skip to content

Commit

Permalink
Fix -fsanitize=alignment issue in numpy/_core/src/multiarray/arraytyp…
Browse files Browse the repository at this point in the history
…es.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).
  • Loading branch information
hawkinsp committed Nov 13, 2023
1 parent 676534c commit fa21c58
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/_core/src/multiarray/arraytypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -2856,7 +2856,7 @@ OBJECT_nonzero (PyObject **ip, PyArrayObject *ap)
}
else {
PyObject *obj;
memcpy(&obj, ip, sizeof(obj));
memcpy(&obj, (void *)ip, sizeof(obj));
if (obj == NULL) {
return NPY_FALSE;
}
Expand Down

0 comments on commit fa21c58

Please sign in to comment.