[libcamera-devel,v2,2/4] simple-cam: Early return if no cameras are found on the system.
diff mbox series

Message ID 20201201174314.12774-3-email@uajain.com
State Accepted
Delegated to: Kieran Bingham
Headers show
Series
  • simple-cam: Provide event-loop backed by libevent
Related show

Commit Message

Umang Jain Dec. 1, 2020, 5:43 p.m. UTC
Failing to do so, the codepath will segfault while trying to acquire
a non-existent camera.

Signed-off-by: Umang Jain <email@uajain.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 simple-cam.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Laurent Pinchart Dec. 1, 2020, 6:19 p.m. UTC | #1
Hi Umang,

Thank you for the patch.

s/\.$// on the subject line.

On Tue, Dec 01, 2020 at 11:13:12PM +0530, Umang Jain wrote:
> Failing to do so, the codepath will segfault while trying to acquire
> a non-existent camera.
> 
> Signed-off-by: Umang Jain <email@uajain.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  simple-cam.cpp | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/simple-cam.cpp b/simple-cam.cpp
> index e88fb85..f844ff4 100644
> --- a/simple-cam.cpp
> +++ b/simple-cam.cpp
> @@ -307,6 +307,13 @@ int main()
>  	for (std::unique_ptr<Request> &request : requests)
>  		camera->queueRequest(request.get());
>  
> +	if(!cm->cameras().size()) {

Missing space after if. Doesn't checkstyle.py warn you ? Ah, no, we have
no checkstyle.py for simple-cam :-)

> +		std::cout << "No cameras were identified on the system."
> +			  << std::endl;
> +		cm->stop();
> +		return EXIT_FAILURE;
> +	}
> +
>  	/*
>  	 * --------------------------------------------------------------------
>  	 * Run an EventLoop

Patch
diff mbox series

diff --git a/simple-cam.cpp b/simple-cam.cpp
index e88fb85..f844ff4 100644
--- a/simple-cam.cpp
+++ b/simple-cam.cpp
@@ -307,6 +307,13 @@  int main()
 	for (std::unique_ptr<Request> &request : requests)
 		camera->queueRequest(request.get());
 
+	if(!cm->cameras().size()) {
+		std::cout << "No cameras were identified on the system."
+			  << std::endl;
+		cm->stop();
+		return EXIT_FAILURE;
+	}
+
 	/*
 	 * --------------------------------------------------------------------
 	 * Run an EventLoop