From patchwork Tue Mar 25 18:08:14 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: 23020 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id C4DE9C323E for ; Tue, 25 Mar 2025 19:20:38 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 56ECC353 for ; Tue, 25 Mar 2025 20:18:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742930331; bh=ySDDXkgoPdzwPs6BoIxoTD3UqhqnC2eULU57oLYyKqU=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Resent-From:Resent-To:From; b=n0Qf9gYmazO6F3KspIK06H3QR0KyvJqhBx2X9rUiGH1Uo6mQd49pxrnYqanNHFpLz CqGGct6cpu/jdu0l40EEBQFCOvDLw19opQlgMeRJLOT7Ojw4bijYi99Q3YCpKtr3Un Uh8U40DonFx/5rEedgYpWroCz7qfsT34+5rMvaro= Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id KK2/Bsjw4mfwuS8A4E0KoQ (envelope-from ) for ; Tue, 25 Mar 2025 19:07:04 +0100 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id E6E21353; Tue, 25 Mar 2025 19:07:03 +0100 (CET) Authentication-Results: perceval.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.a=rsa-sha256 header.s=mail header.b=g4VJXIQZ; dkim-atps=neutral Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B5CCE68960; Tue, 25 Mar 2025 19:08:48 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="g4VJXIQZ"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DD97568957 for ; Tue, 25 Mar 2025 19:08:43 +0100 (CET) Received: from pb-laptop.local (185.221.143.221.nat.pool.zt.hu [185.221.143.221]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0DC89353 for ; Tue, 25 Mar 2025 19:06:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1742926016; bh=fBLhKYdPjRhaI/DNIgvU+LareB5sr4B2UxeoLiLrgWI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=g4VJXIQZ2LNhHK/LlpAI4R3gFR3M1ra0k2HJrFhJ5TgBemzftF0L9LU82wSOMwJvm /R+aIydTyQ20mxvDHvEYyclzToiy2quSN30xw7yqwHc849AwWqINbVq2taCrWfS4BB +OTUgUBUOTAg8y+2ckSvrantQE8hKLY/Vnj29Yk8= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v3 2/9] libcamera: process: Misc. cleanup around `execv()` Date: Tue, 25 Mar 2025 19:08:14 +0100 Message-ID: <20250325180821.1456154-3-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250325180821.1456154-1-barnabas.pocze@ideasonboard.com> References: <20250325180821.1456154-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" X-TUID: kdcxRDvFkBCb Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org 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: 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..567b878d4 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(); + 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); }