cam: file_sink: Workaround gcc-13 dangling-reference false positive

A new warning has been introduced to gcc-13 that produces a false
positive on the cam file sink object:

src/cam/file_sink.cpp:92:45: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
   92 |                 const FrameMetadata::Plane &meta = buffer->metadata().planes()[i];
      |                                             ^~~~
src/cam/file_sink.cpp:92:81: note: the temporary was destroyed at the end of the full expression '(& buffer->libcamera::FrameBuffer::metadata())->libcamera::FrameMetadata::planes().libcamera::Span<const libcamera::FrameMetadata::Plane>::operator[](i)'
   92 |                 const FrameMetadata::Plane &meta = buffer->metadata().planes()[i];
      |                                                                                 ^
cc1plus: all warnings being treated as errors

Workaround this issue by refactoring the code to take a local const
copy of the bytesused value, rather than a local const reference to the
plane.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=185
Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107532
Co-developed-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Eric Curtin <ecurtin@redhat.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
[Kieran: Commit and comment reworded prior to merge]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Eric Curtin 2023-02-20 04:55:24 +00:00 committed by Kieran Bingham
parent af7d6a4c2d
commit 13759e1006

View file

@ -114,13 +114,18 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer,
} }
for (unsigned int i = 0; i < buffer->planes().size(); ++i) { for (unsigned int i = 0; i < buffer->planes().size(); ++i) {
const FrameMetadata::Plane &meta = buffer->metadata().planes()[i]; /*
* This was formerly a local "const FrameMetadata::Plane &"
* however this causes a false positive warning for dangling
* references on gcc 13.
*/
const unsigned int bytesused = buffer->metadata().planes()[i].bytesused;
Span<uint8_t> data = image->data(i); Span<uint8_t> data = image->data(i);
unsigned int length = std::min<unsigned int>(meta.bytesused, data.size()); const unsigned int length = std::min<unsigned int>(bytesused, data.size());
if (meta.bytesused > data.size()) if (bytesused > data.size())
std::cerr << "payload size " << meta.bytesused std::cerr << "payload size " << bytesused
<< " larger than plane size " << data.size() << " larger than plane size " << data.size()
<< std::endl; << std::endl;