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 1B801428E8; Fri, 7 Apr 2023 21:25:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E36BC40E0F; Fri, 7 Apr 2023 21:25:38 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id A5F5040E03 for ; Fri, 7 Apr 2023 21:25:37 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id D05F9213B62E; Fri, 7 Apr 2023 12:25:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D05F9213B62E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680895536; bh=rgaU0IBIrrQ8kibPSPZmCivzXs0LzPCMFmlLc2PHzDs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=M7KEdB6ZBVVJ7jjvEHF+XGhMEnyHZBco1s9cKJQiR+Eu5hGjrCnyA4gbHWSnCsjDH 11+mKCl0riZmljnBbdmrYnketNKXlA38we8+bDhI0hf3jNmS92BP85T8nJWHrQ5yT/ TsgwVYeTz/Hm00qvfiOQdeSkLdje+hyzOVXoTYtI= Date: Fri, 7 Apr 2023 12:25:36 -0700 From: Tyler Retzlaff To: Bruce Richardson Cc: dev@dpdk.org, ciara.power@intel.com Subject: Re: [PATCH v3 2/5] telemetry: remove variable length array in printf fn Message-ID: <20230407192536.GC3014@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20230310181836.162336-1-bruce.richardson@intel.com> <20230405160326.186921-1-bruce.richardson@intel.com> <20230405160326.186921-3-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405160326.186921-3-bruce.richardson@intel.com> 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 Wed, Apr 05, 2023 at 05:03:23PM +0100, Bruce Richardson wrote: > The json_snprintf function, used to add json characters on to a buffer, > leaving the buffer unmodified in case of error, used a variable length > array to store the data temporarily while checking for overflow. VLAs > can be unsafe, and are unsupported by some compilers, so remove use of > the VLA. > > For the normal case where there is only a small amount of existing text > in the buffer (<4 chars) to be preserved, save that off temporarily to a > local array, and restore on error. To handle cases where there is more > than a few characters in the buffer, we use the existing logic of doing > the print to a temporary buffer initially and then copying. In this > case, though we use malloc-allocated buffer rather than VLA. > > Within the unit tests, the "telemetry_data_autotests" test cases - which > mimic real telemetry use - all exercise the first path. The > telemetry_json_autotest cases work directly with generating json, and > use uninitialized buffers so also test the second, malloc-allocated > buffer, cases. > > Signed-off-by: Bruce Richardson > > --- Acked-by: Tyler Retzlaff