[PATCH 1/2] telemetry: use malloc instead of variable length array
Tyler Retzlaff
roretzla at linux.microsoft.com
Mon Apr 3 22:40:46 CEST 2023
On Mon, Apr 03, 2023 at 01:19:12PM -0700, Stephen Hemminger wrote:
> On Mon, 3 Apr 2023 09:30:23 -0700
> Tyler Retzlaff <roretzla at linux.microsoft.com> 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.
More information about the dev
mailing list