Re: [PATCH v25 01/16] trace-cmd: Replace time sync protocol ID with string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 29 Oct 2020 13:18:01 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote:
> +static int make_trace_req_protos(char **buf, int *size, char **tsync_protos)
>  {
> +	int protos_size = 1;
>  	size_t buf_size;
> +	char **protos;
>  	char *nbuf;
>  	char *p;
>  
> +	protos = tsync_protos;
> +	while (*protos) {
> +		protos_size += strlen(*protos) + 1;
> +		protos++;
> +	}
> +
>  	buf_size = TRACE_REQ_PARAM_SIZE + protos_size;
>  	nbuf = realloc(*buf, *size + buf_size);
>  	if (!nbuf)
> @@ -867,7 +875,13 @@ static int make_trace_req_protos(char **buf, int *size,
>  	*(unsigned int *)p = htonl(protos_size);
>  	p += sizeof(int);
>  
> -	memcpy(p, tsync_protos, protos_size);
> +	protos = tsync_protos;
> +	while (*protos) {
> +		memcpy(p, *protos, strlen(*protos) + 1);

The above can be replaced with:

		strcpy(p, *protos);

-- Steve

> +		p += strlen(*protos) + 1;
> +		protos++;
> +	}
> +	p = NULL;
>  
> 



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux