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 0C159428E8; Fri, 7 Apr 2023 21:50:09 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D6FFA40E0F; Fri, 7 Apr 2023 21:50:08 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 5E85040E03 for ; Fri, 7 Apr 2023 21:50:07 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id B128721345FF; Fri, 7 Apr 2023 12:50:06 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B128721345FF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680897006; bh=QGl6yynHD5ZHqwjak8sr07ljYcYsjfvx4egdNYTCP4w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RVM7rXLBuiIQHh2lN7Paa1EXbuOPwPDf8UbPhiBniB+60mRchrUWot8/+QyVBrycC m+lQ5pIy4OXuAU4lDQ6HtJBFIKDkdV1dRVeWixRXzB4Ku2lk251A+YbP+acLUrfWbQ A1nV92LsIGa3iSejZVZQX+kwcDptx0IpEsJy8Jhw= Date: Fri, 7 Apr 2023 12:50:06 -0700 From: Tyler Retzlaff To: Bruce Richardson Cc: dev@dpdk.org, ciara.power@intel.com Subject: Re: [PATCH v3 4/5] telemetry: rename local variables Message-ID: <20230407195006.GE3014@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20230310181836.162336-1-bruce.richardson@intel.com> <20230405160326.186921-1-bruce.richardson@intel.com> <20230405160326.186921-5-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405160326.186921-5-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:25PM +0100, Bruce Richardson wrote: > In the newly separated out function, rename "tmp" to "buf" to have more > meaningful variable names. > > Signed-off-by: Bruce Richardson > > --- Acked-by: Tyler Retzlaff (with suggestions) > > When committing, this patch can be merged with the previous. I've kept > them separate for now, as it makes reviewing a lot easier. > --- > lib/telemetry/telemetry_json.h | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) > > diff --git a/lib/telemetry/telemetry_json.h b/lib/telemetry/telemetry_json.h > index aada523a27..c087b833eb 100644 > --- a/lib/telemetry/telemetry_json.h > +++ b/lib/telemetry/telemetry_json.h > @@ -84,44 +84,44 @@ static const char control_chars[0x20] = { > * directly, but returns 0 on overflow. Otherwise returns number of chars written to buffer. > */ > static inline int > -__json_format_str_to_buf(char *tmp, const int len, > +__json_format_str_to_buf(char *buf, const int len, > const char *prefix, const char *str, const char *suffix) does it cascade rubbish into the caller if `len` is made to be type `size_t` instead of `int`? > { > - int tmpidx = 0; > + int bufidx = 0; > > - while (*prefix != '\0' && tmpidx < len) > - tmp[tmpidx++] = *prefix++; > - if (tmpidx >= len) > + while (*prefix != '\0' && bufidx < len) > + buf[bufidx++] = *prefix++; > + if (bufidx >= len) > return 0; > > while (*str != '\0') { > if (*str < (int)RTE_DIM(control_chars)) { > int idx = *str; /* compilers don't like char type as index */ should be `size_t` instead of `int` type for idx. > if (control_chars[idx] != 0) { > - tmp[tmpidx++] = '\\'; > - tmp[tmpidx++] = control_chars[idx]; > + buf[bufidx++] = '\\'; > + buf[bufidx++] = control_chars[idx]; > } > } else if (*str == '"' || *str == '\\') { > - tmp[tmpidx++] = '\\'; > - tmp[tmpidx++] = *str; > + buf[bufidx++] = '\\'; > + buf[bufidx++] = *str; > } else > - tmp[tmpidx++] = *str; > + buf[bufidx++] = *str; > /* we always need space for (at minimum) closing quote and null character. > * Ensuring at least two free characters also means we can always take an > * escaped character like "\n" without overflowing > */ > - if (tmpidx > len - 2) > + if (bufidx > len - 2) > return 0; > str++; > } > > - while (*suffix != '\0' && tmpidx < len) > - tmp[tmpidx++] = *suffix++; > - if (tmpidx >= len) > + while (*suffix != '\0' && bufidx < len) > + buf[bufidx++] = *suffix++; > + if (bufidx >= len) > return 0; > > - tmp[tmpidx] = '\0'; > - return tmpidx; > + buf[bufidx] = '\0'; > + return bufidx; > } > > /** > -- > 2.37.2