Skip to content
Commit bf1bcb68 authored by Alexander Richardson's avatar Alexander Richardson Committed by Louis Dionne
Browse files

[libc++] Use intptr_t instead of ptrdiff_t for messages_base::catalog

On GLibc, FreeBSD and macOS systems nl_catd is a pointer type, and
round-tripping this in a variable of ptrdiff_t is not portable.
In fact such a round-trip yields a non-dereferenceable pointer on
CHERI-enabled architectures such as Arm Morello. There pointers (and
therefore intptr_t) are twice the size of ptrdiff_t, which means casting
to ptrdiff_t strips the high (metadata) bits (as well as a hidden pointer
validity bit).

Since catalog is now guaranteed to be the same size or larger than nl_catd,
we can store all return values safely and the shifting workaround from
commit 0c68ed00 should not be needed
anymore (this is also not portable to CHERI systems on since shifting a
valid pointer right will create a massively out-of-bounds pointer that
may not be representable).

This can be fixed by using intptr_t which should be the same type as
ptrdiff_t on all currently supported architectures.

See also: https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2028

Differential Revision: https://reviews.llvm.org/D134420



Co-authored-by: default avatarLouis Dionne <ldionne.2@gmail.com>
parent dd5af895
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment