From patchwork Thu Feb 1 05:08:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khem Raj X-Patchwork-Id: 19473 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 B44DBC32A9 for ; Thu, 1 Feb 2024 05:08:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72DFF62808; Thu, 1 Feb 2024 06:08:18 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NuWvAFHE"; dkim-atps=neutral Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AB86B62801 for ; Thu, 1 Feb 2024 06:08:15 +0100 (CET) Received: by mail-ot1-x331.google.com with SMTP id 46e09a7af769-6e1196dc31bso242073a34.3 for ; Wed, 31 Jan 2024 21:08:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706764094; x=1707368894; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=42Vq7L+2Kae/lqnZWnj9ncsGRvaauD5Mm3MRrwUL/Jg=; b=NuWvAFHEqjvi1up/+0MTenjdhL/O3poru+OtdG9lGHnC6gn/YYFQoXD577HhxsE0vR gZOVUZGeEs+964lsJsNPOtK9Fos6FadYPUaotFTUr6gzeMTsWMe+GEB4m5ew7X1ESYO5 T3agkweXfITgI/pR6xIRsjIWQ3l2wsJhzcnbhwN97LtHIoiGG9Fjyz8lNP3q609HdsaE 0WmWZoijWbtSNW7QwtcQbgagzoevWhkVxG+82wOdTEDC3KyuyY0NLkOf0Ewv6lUwAOyA tq52ejvlfYUAUOgaVE/u6Dx2vvS92a69rBtj9luUuaLIGVdCzk2bjbNsowa+zi9+J6yZ IWGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706764094; x=1707368894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=42Vq7L+2Kae/lqnZWnj9ncsGRvaauD5Mm3MRrwUL/Jg=; b=eFAjg6777OR0JEcrfhQj1JDbXcRkPPkOgZIWQd6ouAR53MgjXLg5rAsw9eS50MEg0w xSIYSJILd3NpzAJEw5IpURqARxi/Eo8VyU3UXUwdbWG+NSb2JjBYg6Jg35ykhJnUfNHI VWCojfA3cEcC2i+RPuB4oC4B5wD0F/sW5T6pUA47+0ACL661pRjbO6L67LXMpeMaLvYN KF4h5HiInmvGeq5jSyfhrOAHlelRA7NAuP8bTxVtYpMlUXzwnMPzZzA2Pa/i5gD1SpOA qhRJ2jzAdajBPdM2Xv8WkYmid5qWhSMX9o4No7rPHQY5zIYlU9S6hrHUcbYkaHqyhkMP XD8g== X-Gm-Message-State: AOJu0YzRjr6Rd2ogMzS/qsQltxLq4JKmNgIIRq6chHdO6Ay8zk6xzXbD TxghfUUp5e/CSQqd/u4X5+AvznpaLI2inB2sJZGh/hE51yOaUdukGbUFhuT/6tM= X-Google-Smtp-Source: AGHT+IEb9yGmocRB4GmRSD2ksovfEemJrQ/eEtRriuNlohi4C4HF/v5d3qu+MC3VVbdwcRpm7q/q6Q== X-Received: by 2002:a05:6359:4206:b0:176:d5b7:344a with SMTP id kn6-20020a056359420600b00176d5b7344amr1792661rwb.29.1706764093944; Wed, 31 Jan 2024 21:08:13 -0800 (PST) Received: from apollo.hsd1.ca.comcast.net ([2601:646:9d80:4380::8157]) by smtp.gmail.com with ESMTPSA id z1-20020aa78881000000b006ddcf451a37sm10803480pfe.75.2024.01.31.21.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 21:08:13 -0800 (PST) From: Khem Raj To: libcamera-devel@lists.libcamera.org Subject: [PATCH 2/2] options: Replace use of VLAs in C++ Date: Wed, 31 Jan 2024 21:08:10 -0800 Message-ID: <20240201050810.3501276-2-raj.khem@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240201050810.3501276-1-raj.khem@gmail.com> References: <20240201050810.3501276-1-raj.khem@gmail.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: , Cc: Khem Raj Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Clang++ 18 is fussy about this with new warning checks. ../git/src/apps/common/options.cpp:882:20: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension] 882 | char shortOptions[optionsMap_.size() * 3 + 2]; | ^~~~~~~~~~~~~~~~~~~~~~~~~~ Therefore replace using VLAs with alloca and malloc/free Signed-off-by: Khem Raj --- src/apps/common/options.cpp | 4 ++-- src/libcamera/ipc_unixsocket.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/apps/common/options.cpp b/src/apps/common/options.cpp index 4f7e8691..b020f603 100644 --- a/src/apps/common/options.cpp +++ b/src/apps/common/options.cpp @@ -879,8 +879,8 @@ OptionsParser::Options OptionsParser::parse(int argc, char **argv) * Allocate short and long options arrays large enough to contain all * options. */ - char shortOptions[optionsMap_.size() * 3 + 2]; - struct option longOptions[optionsMap_.size() + 1]; + char *shortOptions = (char*)alloca(optionsMap_.size() * 3 + 2); + struct option *longOptions = (struct option*)alloca(optionsMap_.size() + 1); unsigned int ids = 0; unsigned int idl = 0; diff --git a/src/libcamera/ipc_unixsocket.cpp b/src/libcamera/ipc_unixsocket.cpp index 1980d374..3a7f8ee6 100644 --- a/src/libcamera/ipc_unixsocket.cpp +++ b/src/libcamera/ipc_unixsocket.cpp @@ -247,8 +247,8 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, iov[0].iov_base = const_cast(buffer); iov[0].iov_len = length; - char buf[CMSG_SPACE(num * sizeof(uint32_t))]; - memset(buf, 0, sizeof(buf)); + char *buf = (char*)malloc(CMSG_SPACE(num * sizeof(uint32_t))); + memset((void*)buf, 0, sizeof(buf)); struct cmsghdr *cmsg = (struct cmsghdr *)buf; cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); @@ -270,9 +270,11 @@ int IPCUnixSocket::sendData(const void *buffer, size_t length, int ret = -errno; LOG(IPCUnixSocket, Error) << "Failed to sendmsg: " << strerror(-ret); + free(buf); return ret; } + free(buf); return 0; } @@ -283,8 +285,8 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, iov[0].iov_base = buffer; iov[0].iov_len = length; - char buf[CMSG_SPACE(num * sizeof(uint32_t))]; - memset(buf, 0, sizeof(buf)); + char *buf = (char*)malloc(CMSG_SPACE(num * sizeof(uint32_t))); + memset((void*)buf, 0, sizeof(buf)); struct cmsghdr *cmsg = (struct cmsghdr *)buf; cmsg->cmsg_len = CMSG_LEN(num * sizeof(uint32_t)); @@ -305,12 +307,14 @@ int IPCUnixSocket::recvData(void *buffer, size_t length, if (ret != -EAGAIN) LOG(IPCUnixSocket, Error) << "Failed to recvmsg: " << strerror(-ret); + free(buf); return ret; } if (fds) memcpy(fds, CMSG_DATA(cmsg), num * sizeof(uint32_t)); + free(buf); return 0; }