span: diagnose dangling views from MakeByteSpan/MakeUCharSpan

bitcoin/bitcoin: PR #36183

1 suggestion

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · Chained span conversions lose the new lifetime dependency

Chained conversions bypass the new Clang lifetime annotation; no current caller producing this input was found, and the underlying dangling-span behavior predates this PR.

Location: src/span.h:121 (head).

Details and suggested fix

For example, auto s = MakeUCharSpan(MakeByteSpan(std::vector<std::byte>{std::byte{1}})); selects the annotated inner overload, but its returned std::span selects the unannotated borrowed-range outer overload. The outer call therefore loses the lifetime dependency, and s dangles when the vector is destroyed at the semicolon. Calling the annotated UCharCast inside the helper does not propagate that dependency across the helper's public boundary. The reverse helper chain has the same limitation.

Document this limitation if these overloads remain unchanged. Alternatively, consider span-specific by-value overloads with LIFETIMEBOUND, matching UCharCast, and verify their diagnostics with Clang. That alternative has not been experimentally validated and must preserve valid stored conversions of prvalue views, such as MakeUCharSpan(tester.GetCipher().GetSendGarbageTerminator()) in net_tests.cpp; simply annotating the borrowed const V& overload would tie the result to the temporary view object.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.