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 34B90428C9; Mon, 3 Apr 2023 22:19:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 104294067E; Mon, 3 Apr 2023 22:19:17 +0200 (CEST) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by mails.dpdk.org (Postfix) with ESMTP id F101640156 for ; Mon, 3 Apr 2023 22:19:15 +0200 (CEST) Received: by mail-pl1-f178.google.com with SMTP id kq3so29184805plb.13 for ; Mon, 03 Apr 2023 13:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1680553155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=hthVAwAV9UJvtZjsJwvfCi/cVLI2T/Cefjdg1dN1rtE=; b=bI4EQAzcvkI1DCwHQDeCWT6apNfIjbB/2odbSKj3TEMxc0fBs0a84yfZHE0c2uunPO KhXDvbMT+7CX1ULNAaLZ05wMVz/A3D94jKG+RFgO3VNU6gHD+vO1NiisoLgYTNTFGfLS Fij+j1Cn+UyI5PCRIyVw12bDO4ciNImKHMj0ZBBOkHOv1K31RZCNIXCzqwYEfbJ/Itlj 9LVKLdjK38sAhtG/b60umUxDkQ341zCmzHlWdSOhBzoMqrMskDLyo9cIYFXrvidXvFSc laLMgIVAnB8RzPV3GPQN/VqfImxorMxlNX9gvVMzqFrQoTM1+fFjqDsxFdogBW/X2ruS Hdcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680553155; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hthVAwAV9UJvtZjsJwvfCi/cVLI2T/Cefjdg1dN1rtE=; b=FTGE/c/07Ozsnf0LwDPCY/VXkLgstOQVdKvMhnzHdqMZO/opP//YhQeZ/mSBejZo9T 7AaBw86BEVejk3nctS8ct57O7ad8YstF2xtCBXS4cmMvet/Ya1qSpqXPtfH5aPm78pW1 2FUXS15QthRk56Lw2tdqCVH4Jez5BlgeoNeyFyshKsF1iHu+wN3TnAAc96GfrXUsPF3n T02I8lSa3c98yq1fJkYHKE6fnQjTwh1z2m32DU+kVVDYeZzkOcGTLfXq1oM/ahEP95uK mgVDTMwb+xNB32X5m5sqf6J8K0oMz5lDy7Wdw3krWWgLtc9u7jeB8uGFsxQWIDwLPoRu xtrg== X-Gm-Message-State: AAQBX9cd3FMK0uBdKO/kA32n7pDzroM76usD6+KzQLmUhOPdw7MUInoQ 0TdnZpV5Z4py6CkpA9402Yi7DA== X-Google-Smtp-Source: AKy350Z94jsTGyeA6NZDDpoH1IeLO7RLVPSw6q+IGv0YlXBA/mjpME0zAK2dFNyfSQlz/EtHokwMKw== X-Received: by 2002:a17:90b:4ac7:b0:237:8417:d9e3 with SMTP id mh7-20020a17090b4ac700b002378417d9e3mr161340pjb.15.1680553154989; Mon, 03 Apr 2023 13:19:14 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id j6-20020a17090a31c600b00233b196fe30sm9966715pjf.20.2023.04.03.13.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 13:19:14 -0700 (PDT) Date: Mon, 3 Apr 2023 13:19:12 -0700 From: Stephen Hemminger To: Tyler Retzlaff 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: <20230403131913.0aec54ce@hermes.local> In-Reply-To: <1680539424-20255-2-git-send-email-roretzla@linux.microsoft.com> References: <1680539424-20255-1-git-send-email-roretzla@linux.microsoft.com> <1680539424-20255-2-git-send-email-roretzla@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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, 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) { > strcpy(buf, tmp); > - return ret; > } > - return 0; /* nothing written or modified */ > + > + free(tmp); > + > + return ret; > } Not sure why it needs a tmp buffer anyway?