From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E12A4428C3; Mon, 3 Apr 2023 22:40:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6F5424067E; Mon, 3 Apr 2023 22:40:49 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id A57B640156 for ; Mon, 3 Apr 2023 22:40:47 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id DDCCB20FD075; Mon, 3 Apr 2023 13:40:46 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DDCCB20FD075 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680554446; bh=Pqwzy2Uih8grRdCSEf1hmjz5GkEMKzcgcTVP2VOVWh8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o+UhOJb4PHUk8coS3+4s9fwAUHh30vNtfo2s5//izNQhCKAb4ZDav0ozD6KJEbS5o hfMen8Ficj4m7pobJ+FTcFkkLVy3/oHdoh36bp386hOdqNB1xMZOIP5LFAxYiztzEo 5Xm1UaB9K14YviE8ngBs45zNgGL38zqkZudPONdU= Date: Mon, 3 Apr 2023 13:40:46 -0700 From: Tyler Retzlaff To: Stephen Hemminger Cc: dev@dpdk.org, ciara.power@intel.com, bruce.richardson@intel.com, david.marchand@redhat.com, thomas@monjalon.net Subject: Re: [PATCH 1/2] telemetry: use malloc instead of variable length array Message-ID: <20230403204046.GA30448@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1680539424-20255-1-git-send-email-roretzla@linux.microsoft.com> <1680539424-20255-2-git-send-email-roretzla@linux.microsoft.com> <20230403131913.0aec54ce@hermes.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230403131913.0aec54ce@hermes.local> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Mon, Apr 03, 2023 at 01:19:12PM -0700, Stephen Hemminger wrote: > On Mon, 3 Apr 2023 09:30:23 -0700 > Tyler Retzlaff wrote: > > > __json_snprintf(char *buf, const int len, const char *format, ...) > > { > > - char tmp[len]; > > + char *tmp = malloc(len); > > va_list ap; > > - int ret; > > + int ret = 0; > > + > > + if (tmp == NULL) > > + return ret; > > > > va_start(ap, format); > > ret = vsnprintf(tmp, sizeof(tmp), format, ap); > > va_end(ap); > > if (ret > 0 && ret < (int)sizeof(tmp) && ret < len) { ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ also this seems redundant. when is len != sizeof(tmp) here? > > strcpy(buf, tmp); > > - return ret; > > } > > - return 0; /* nothing written or modified */ > > + > > + free(tmp); > > + > > + return ret; > > } > > Not sure why it needs a tmp buffer anyway? yeah, there a are a few question marks in this code. i've removed this patch from the series for now. v3 doesn't touch this file anymore.