[alsa-devel] [PATCH v2 07/13] topology: Add private data parser

Liam Girdwood liam.r.girdwood at linux.intel.com
Tue Jul 7 17:54:02 CEST 2015


On Wed, 2015-07-01 at 18:20 +0200, Takashi Iwai wrote:

> 
> > +static int get_hex_num(const char *str)
> > +{
> > +	char *tmp, *s = NULL;
> > +	int i = 0;
> > +
> > +	tmp = strdup(str);
> > +	if (tmp == NULL)
> > +		return -ENOMEM;
> > +
> > +	s = strtok(tmp, ",");
> > +	while (s != NULL) {
> > +		s = strtok(NULL, ",");
> > +		i++;
> > +	}
> > +
> > +	free(tmp);
> > +	return i;
> 
> Hmm, this just counts the number of comma + 1, so you don't need to
> duplicate the string?
> 

The string here is duplicated since strtok is destructive (it overwrites
the delimiters with NULL) and the string is being used later on by the
calling function.

Liam



More information about the Alsa-devel mailing list