From 13759e1006b0133d20e9f6b1ce44ce9751f3d41d Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Mon, 20 Feb 2023 04:55:24 +0000 Subject: 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::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 Signed-off-by: Eric Curtin Reviewed-by: Kieran Bingham [Kieran: Commit and comment reworded prior to merge] Signed-off-by: Kieran Bingham --- src/apps/cam/file_sink.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/apps/cam') diff --git a/src/apps/cam/file_sink.cpp b/src/apps/cam/file_sink.cpp index b32aad24..dca350c4 100644 --- a/src/apps/cam/file_sink.cpp +++ b/src/apps/cam/file_sink.cpp @@ -114,13 +114,18 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer, } 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 data = image->data(i); - unsigned int length = std::min(meta.bytesused, data.size()); + const unsigned int length = std::min(bytesused, data.size()); - if (meta.bytesused > data.size()) - std::cerr << "payload size " << meta.bytesused + if (bytesused > data.size()) + std::cerr << "payload size " << bytesused << " larger than plane size " << data.size() << std::endl; -- cgit v1.2.1