Re: [Rd] R should add an API routine for safe use of memcpy(), memset() for use with 0-length SEXP

2025-04-23 Thread Tomas Kalibera
On 4/24/25 00:18, Michael Chirico wrote: In that case it seems like just erroring instead of returning invalid pointers is a much friendlier option. Why give developers an unpinned grenade to carry around? That would be too strict at this point. There is too much code around depending on tha

Re: [Rd] R should add an API routine for safe use of memcpy(), memset() for use with 0-length SEXP

2025-04-23 Thread Michael Chirico
In that case it seems like just erroring instead of returning invalid pointers is a much friendlier option. Why give developers an unpinned grenade to carry around? On Wed, Apr 23, 2025 at 1:38 PM Tomas Kalibera wrote: > > On 4/23/25 19:03, Michael Chirico wrote: > > h/t Tim Taylor for pointing o

Re: [Rd] R should add an API routine for safe use of memcpy(), memset() for use with 0-length SEXP

2025-04-23 Thread Michael Chirico
h/t Tim Taylor for pointing out my blindspot :) We have Memcpy() in API already [1], which wraps a 0-aware R_chk_memcpy() [2]. We don't quite have Memset() in API, though; instead we have Memzero() [3] for R_chk_memset(s, 0, n) which is 0-aware memset() [4]. [1] https://github.com/r-devel/r-svn

[Rd] R should add an API routine for safe use of memcpy(), memset() for use with 0-length SEXP

2025-04-23 Thread Michael Chirico
>From R 4.5.0 [1], all builds of R discourage use of INTEGER() [and friends REAL(), ... and *_RO() equivalents] on length-0 SEXP [2]. Before R 4.5.0, this was the behavior under --enable-strict-barrier. That means the following can segfault under strict builds (e.g. -fsanitize=alignment and -O0):