Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-05 Thread Bruce Richardson
On Wed, Apr 05, 2023 at 08:25:21AM -0700, Tyler Retzlaff wrote: > On Wed, Apr 05, 2023 at 09:54:46AM +0100, Bruce Richardson wrote: > > On Tue, Apr 04, 2023 at 06:04:32PM -0700, Stephen Hemminger wrote: > > > On Tue, 4 Apr 2023 09:47:21 +0100 > > > Bruce Richardson wrote: > > > > > > > My suggest

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-05 Thread Stephen Hemminger
On Wed, 5 Apr 2023 18:30:51 +0300 Dmitry Kozlyuk wrote: > 2023-04-05 08:25 (UTC-0700), Tyler Retzlaff: > > On Wed, Apr 05, 2023 at 09:54:46AM +0100, Bruce Richardson wrote: > > > On Tue, Apr 04, 2023 at 06:04:32PM -0700, Stephen Hemminger wrote: > > > > On Tue, 4 Apr 2023 09:47:21 +0100 > >

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-05 Thread Dmitry Kozlyuk
2023-04-05 08:25 (UTC-0700), Tyler Retzlaff: > On Wed, Apr 05, 2023 at 09:54:46AM +0100, Bruce Richardson wrote: > > On Tue, Apr 04, 2023 at 06:04:32PM -0700, Stephen Hemminger wrote: > > > On Tue, 4 Apr 2023 09:47:21 +0100 > > > Bruce Richardson wrote: > > > > > > > My suggestion is to use a

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-05 Thread Tyler Retzlaff
On Wed, Apr 05, 2023 at 09:54:46AM +0100, Bruce Richardson wrote: > On Tue, Apr 04, 2023 at 06:04:32PM -0700, Stephen Hemminger wrote: > > On Tue, 4 Apr 2023 09:47:21 +0100 > > Bruce Richardson wrote: > > > > > My suggestion is to use a combination of these methods. In json_snprintf > > > check i

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-05 Thread Bruce Richardson
On Tue, Apr 04, 2023 at 06:04:32PM -0700, Stephen Hemminger wrote: > On Tue, 4 Apr 2023 09:47:21 +0100 > Bruce Richardson wrote: > > > My suggestion is to use a combination of these methods. In json_snprintf > > check if the input buffer is empty or has only one character in it, and use > > metho

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-05 Thread Bruce Richardson
On Tue, Apr 04, 2023 at 06:20:04PM -0700, Stephen Hemminger wrote: > On Tue, 4 Apr 2023 10:34:01 -0700 > Tyler Retzlaff wrote: > > > > > > I think suggestion #2 above should cover most cases, in which case > > > > > using > > > > > your original suggestion of malloc would be ok too for the rare

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Stephen Hemminger
On Tue, 4 Apr 2023 10:34:01 -0700 Tyler Retzlaff wrote: > > > > I think suggestion #2 above should cover most cases, in which case using > > > > your original suggestion of malloc would be ok too for the rare case (if > > > > ever) where we don't just have one terminator on the end. > > > > >

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Stephen Hemminger
On Tue, 4 Apr 2023 09:47:21 +0100 Bruce Richardson wrote: > My suggestion is to use a combination of these methods. In json_snprintf > check if the input buffer is empty or has only one character in it, and use > method #2 if so. If that's not the case, then fallback to method #1 and do > a doubl

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Tyler Retzlaff
On Tue, Apr 04, 2023 at 06:25:42PM +0100, Bruce Richardson wrote: > On Tue, Apr 04, 2023 at 09:44:46AM -0700, Tyler Retzlaff wrote: > > On Tue, Apr 04, 2023 at 05:28:29PM +0100, Bruce Richardson wrote: > > > On Tue, Apr 04, 2023 at 09:24:44AM -0700, Tyler Retzlaff wrote: > > > > On Tue, Apr 04, 202

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Bruce Richardson
On Tue, Apr 04, 2023 at 09:44:46AM -0700, Tyler Retzlaff wrote: > On Tue, Apr 04, 2023 at 05:28:29PM +0100, Bruce Richardson wrote: > > On Tue, Apr 04, 2023 at 09:24:44AM -0700, Tyler Retzlaff wrote: > > > On Tue, Apr 04, 2023 at 09:47:21AM +0100, Bruce Richardson wrote: > > > > On Mon, Apr 03, 202

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Tyler Retzlaff
On Tue, Apr 04, 2023 at 05:28:29PM +0100, Bruce Richardson wrote: > On Tue, Apr 04, 2023 at 09:24:44AM -0700, Tyler Retzlaff wrote: > > On Tue, Apr 04, 2023 at 09:47:21AM +0100, Bruce Richardson wrote: > > > On Mon, Apr 03, 2023 at 01:19:12PM -0700, Stephen Hemminger wrote: > > > > On Mon, 3 Apr 2

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Bruce Richardson
On Tue, Apr 04, 2023 at 09:24:44AM -0700, Tyler Retzlaff wrote: > On Tue, Apr 04, 2023 at 09:47:21AM +0100, Bruce Richardson wrote: > > On Mon, Apr 03, 2023 at 01:19:12PM -0700, Stephen Hemminger wrote: > > > On Mon, 3 Apr 2023 09:30:23 -0700 > > > Tyler Retzlaff wrote: > > > > > > > __json_snp

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Tyler Retzlaff
On Tue, Apr 04, 2023 at 09:47:21AM +0100, Bruce Richardson wrote: > On Mon, Apr 03, 2023 at 01:19:12PM -0700, Stephen Hemminger wrote: > > On Mon, 3 Apr 2023 09:30:23 -0700 > > Tyler Retzlaff wrote: > > > > > __json_snprintf(char *buf, const int len, const char *format, ...) > > > { > > > - ch

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-04 Thread Bruce Richardson
On Mon, Apr 03, 2023 at 01:19:12PM -0700, Stephen Hemminger wrote: > 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

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-03 Thread Tyler Retzlaff
On Mon, Apr 03, 2023 at 01:19:12PM -0700, Stephen Hemminger wrote: > 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

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-03 Thread Stephen Hemminger
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

Re: [PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-03 Thread Tyler Retzlaff
On Mon, Apr 03, 2023 at 09:30:23AM -0700, Tyler Retzlaff wrote: > Replace use of variable length array optional standard feature to > improve portability. > > Signed-off-by: Tyler Retzlaff > --- > lib/telemetry/telemetry_json.h | 32 +++- > 1 file changed, 23 insertio

[PATCH 1/2] telemetry: use malloc instead of variable length array

2023-04-03 Thread Tyler Retzlaff
Replace use of variable length array optional standard feature to improve portability. Signed-off-by: Tyler Retzlaff --- lib/telemetry/telemetry_json.h | 32 +++- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/telemetry/telemetry_json.h b/lib/telem