From f9e2df951969f10f1ee1e46fb806942a27db8aca Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 31 Mar 2022 18:08:22 +0300 Subject: libcamera: v4l2_videodevice: Fix potential errno overwrite The errno variable can potentially be overwritten by operator<<(). Store it in a local variable before logging the error message. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- src/libcamera/v4l2_videodevice.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/libcamera') diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp index 009f6d55..0830be80 100644 --- a/src/libcamera/v4l2_videodevice.cpp +++ b/src/libcamera/v4l2_videodevice.cpp @@ -647,14 +647,17 @@ int V4L2VideoDevice::open() */ int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type) { + int ret; + UniqueFD newFd = handle.dup(); if (!newFd.isValid()) { + ret = -errno; LOG(V4L2, Error) << "Failed to duplicate file handle: " - << strerror(errno); - return -errno; + << strerror(-ret); + return ret; } - int ret = V4L2Device::setFd(std::move(newFd)); + ret = V4L2Device::setFd(std::move(newFd)); if (ret < 0) { LOG(V4L2, Error) << "Failed to set file handle: " << strerror(-ret); -- cgit v1.2.1