From patchwork Thu Apr 24 11:40:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 23254 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B0CE4C32A2 for ; Thu, 24 Apr 2025 11:41:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8EFCD68ACE; Thu, 24 Apr 2025 13:41:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="j2HMYSBX"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C25B668ACE for ; Thu, 24 Apr 2025 13:41:07 +0200 (CEST) Received: from pb-laptop.local (185.221.143.16.nat.pool.zt.hu [185.221.143.16]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 811B91440; Thu, 24 Apr 2025 13:41:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1745494865; bh=v+d5do+BDii4mzQmG2m0z5d+XRpJdYj73QV9LWHAWRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j2HMYSBXkK7GhMPUKx9j1VOGpJepOgnR6rYFkJhP+OJgeI/MLvUXgZEuQRT1PyT2R C7GFty4VapFcPdkz/rE4vFSqpfEIcOVswd9ptPSVtMRREJH44AxQbbzW5iBF7/QWwK azcWWaE43J2zNp7Dz1XK+mSqD+odQmDnwBKYFMGs= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart Subject: [RFC PATCH v5 2/9] libcamera: process: Misc. cleanup around `execv()` Date: Thu, 24 Apr 2025 13:40:56 +0200 Message-ID: <20250424114103.451395-3-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250424114103.451395-1-barnabas.pocze@ideasonboard.com> References: <20250424114103.451395-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Firstly, get the number of arguments first, and use that to determine the size of the allocation instead of retrieving it twice. Secondly, use `const_cast` instead of a C-style cast when calling `execv()`. Third, use `size_t` to match the type of `args.size()`. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/process.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcamera/process.cpp b/src/libcamera/process.cpp index 68fad3270..0990b4bdd 100644 --- a/src/libcamera/process.cpp +++ b/src/libcamera/process.cpp @@ -265,14 +265,15 @@ int Process::start(const std::string &path, if (file && strcmp(file, "syslog")) unsetenv("LIBCAMERA_LOG_FILE"); - const char **argv = new const char *[args.size() + 2]; - unsigned int len = args.size(); + const size_t len = args.size(); + auto argv = std::make_unique(len + 2); + argv[0] = path.c_str(); - for (unsigned int i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) argv[i + 1] = args[i].c_str(); argv[len + 1] = nullptr; - execv(path.c_str(), (char **)argv); + execv(path.c_str(), const_cast(argv.get())); exit(EXIT_FAILURE); }