summaryrefslogtreecommitdiff
path: root/src/apps
diff options
context:
space:
mode:
authorEric Curtin <ecurtin@redhat.com>2023-02-20 04:55:24 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2023-05-01 11:39:07 +0100
commit13759e1006b0133d20e9f6b1ce44ce9751f3d41d (patch)
tree2b52d4e97a66f397d92eb39489503e68d330ea6d /src/apps
parentaf7d6a4c2df6c836ecc704ea44b39ea07418d832 (diff)
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>
Diffstat (limited to 'src/apps')
-rw-r--r--src/apps/cam/file_sink.cpp13
1 files changed, 9 insertions, 4 deletions
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<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())
- std::cerr << "payload size " << meta.bytesused
+ if (bytesused > data.size())
+ std::cerr << "payload size " << bytesused
<< " larger than plane size " << data.size()
<< std::endl;