On Mon, 3 Apr 2023 09:30:23 -0700 Tyler Retzlaff <roret...@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) { > strcpy(buf, tmp); > - return ret; > } > - return 0; /* nothing written or modified */ > + > + free(tmp); > + > + return ret; > } Not sure why it needs a tmp buffer anyway?