From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: dev@dpdk.org, ciara.power@intel.com
Subject: Re: [PATCH v3 4/5] telemetry: rename local variables
Date: Fri, 7 Apr 2023 12:50:06 -0700 [thread overview]
Message-ID: <20230407195006.GE3014@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> (raw)
In-Reply-To: <20230405160326.186921-5-bruce.richardson@intel.com>
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 <bruce.richardson@intel.com>
>
> ---
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
(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
next prev parent reply other threads:[~2023-04-07 19:50 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 18:18 [PATCH] telemetry: fix autotest failures on Alpine Bruce Richardson
2023-03-10 19:08 ` Stephen Hemminger
2023-03-13 9:38 ` Bruce Richardson
2023-04-05 15:44 ` [PATCH v2 0/5] telemetry: remove variable length arrays Bruce Richardson
2023-04-05 15:44 ` [PATCH v2 1/5] telemetry: fix autotest failures on Alpine Bruce Richardson
2023-04-07 19:21 ` Tyler Retzlaff
2023-04-11 8:43 ` Bruce Richardson
2023-04-05 15:44 ` [PATCH v2 2/5] telemetry: remove variable length array in printf fn Bruce Richardson
2023-04-05 15:44 ` [PATCH v2 3/5] telemetry: split out body of json string format fn Bruce Richardson
2023-04-05 15:44 ` [PATCH v2 4/5] telemetry: rename local variables Bruce Richardson
2023-04-05 15:44 ` [PATCH v2 5/5] telemetry: remove VLA in json string format function Bruce Richardson
2023-04-05 16:03 ` [PATCH v3 0/5] telemetry: remove variable length arrays Bruce Richardson
2023-04-05 16:03 ` [PATCH v3 1/5] telemetry: fix autotest failures on Alpine Bruce Richardson
2023-04-07 19:22 ` Tyler Retzlaff
2023-04-05 16:03 ` [PATCH v3 2/5] telemetry: remove variable length array in printf fn Bruce Richardson
2023-04-07 19:25 ` Tyler Retzlaff
2023-04-05 16:03 ` [PATCH v3 3/5] telemetry: split out body of json string format fn Bruce Richardson
2023-04-07 19:28 ` Tyler Retzlaff
2023-04-05 16:03 ` [PATCH v3 4/5] telemetry: rename local variables Bruce Richardson
2023-04-07 19:50 ` Tyler Retzlaff [this message]
2023-04-11 8:58 ` Bruce Richardson
2023-04-05 16:03 ` [PATCH v3 5/5] telemetry: remove VLA in json string format function Bruce Richardson
2023-04-07 19:54 ` Tyler Retzlaff
2023-05-25 7:12 ` David Marchand
2023-05-24 20:47 ` [PATCH v3 0/5] telemetry: remove variable length arrays Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230407195006.GE3014@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net \
--to=roretzla@linux.microsoft.com \
--cc=bruce.richardson@intel.com \
--cc=ciara.power@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).