[PATCH v2] app/testpmd: validate dscp and vlan table entries for meter creation

Stephen Hemminger stephen at networkplumber.org
Wed Aug 27 18:05:04 CEST 2025


On Wed, 27 Aug 2025 07:18:37 -0400
Khadem Ullah <14pwcse1224 at uetpeshawar.edu.pk> wrote:

>  
> +static int
> +validate_input_color_table_entries(char *str)
> +{
> +	char *token = strtok_r(str, PARSE_DELIMITER, &str);
> +	for (int i = 0; token != NULL; i++) {
> +		if (i > ((MAX_DSCP_TABLE_ENTRIES + MAX_VLAN_TABLE_ENTRIES) - 1))
> +			return -1;
> +		token = strtok_r(str, PARSE_DELIMITER, &str);
> +	}
> +	return 0;
> +}

The loop doesn't look right, it is looking form next deliminator at
the start of the list? Normally strtok_r is used with a different pointer
as the "saveptr".

From man page.

       The  strtok_r()  function  is  a  reentrant  version of strtok().  The saveptr argument is a
       pointer to a char * variable that is used internally by strtok_r() in order to maintain con‐
       text between successive calls that parse the same string.

       On the first call to strtok_r(), str should point to the string to be parsed, and the  value
       of  *saveptr  is  ignored  (but see VERSIONS).  In subsequent calls, str should be NULL, and
       saveptr (and the buffer that it points to) should be unchanged since the previous call.


More information about the stable mailing list