bkietz opened a new issue, #35581:
URL: https://github.com/apache/arrow/issues/35581
### Describe the bug, including details regarding any error messages,
version, and platform.
`ArraySpan::FillFromScalar` can store pointers into the structure itself
(specifically, into `ArraySpan::scratch_space`) which produces an ArraySpan
which easily be unsafely moved and copied:
```c++
ArraySpan span;
span.FillFromScalar(scalar);
UseSpan(span); // Fine; the original span is still alive.
return span; // Undefined Behavior; the returned copy views
// a stack variable whose lifetime has ended.
```
The capability to view a Scalar as an ArraySpan can be preserved and made
safer by restricting access to the span to an explicitly delineated scope:
```c++
ArraySpan::FillFromScalar(scalar, [&](ArraySpan span) {
UseSpan(span); // Fine; the viewed scratch space is alive inside this
scope.
});
```
This has the pleasant side effect of reducing the size of ArraySpan by 16
bytes.
### Component(s)
C++
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]