[libcamera-devel] [PATCH] file_sink.cpp: Avoid dangling-reference

Kieran Bingham kieran.bingham at ideasonboard.com
Tue Jan 24 16:37:55 CET 2023


Hi Khem,

Quoting Khem Raj via libcamera-devel (2023-01-24 09:22:18)
> Fixes following errors with gcc-13
> 
> ../git/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];
>       |                                             ^~~~
> ../git/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
> 
> Signed-off-by: Khem Raj <raj.khem at gmail.com>

Thanks for identifying and fixing this issue.

Wim has also discovered this today. He reports that your patch does not
apply on the latest libcamera, and looking at the paths below - we moved
src/cam/ into src/apps/cam a few weeks back.

Could you rebase this on top of master please? If you can Cc Wim, who is
also affected by this, I expect he can also test it and we can get it
merged quickly.

Thanks
--
Kieran

> ---
>  src/cam/file_sink.cpp | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp
> index 45213d4a..897c4b37 100644
> --- a/src/cam/file_sink.cpp
> +++ b/src/cam/file_sink.cpp
> @@ -89,13 +89,13 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer)
>         Image *image = mappedBuffers_[buffer].get();
>  
>         for (unsigned int i = 0; i < buffer->planes().size(); ++i) {
> -               const FrameMetadata::Plane &meta = buffer->metadata().planes()[i];
> +               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());
> +               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;
>  
> -- 
> 2.39.1
>


More information about the libcamera-devel mailing list