From: Matthew Fernandez Date: Thu, 14 Jul 2022 14:58:17 +0000 (-0700) Subject: cgraph tok: add extra check for duplicate separator characters X-Git-Tag: 5.0.1~35^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3124dcdd2c947b0ff601ba11013965f3cf565f65;p=graphviz cgraph tok: add extra check for duplicate separator characters When a user supplies the same character more than once when constructing a tokenizer, nothing is functionally incorrect but this is strong indicator of a bug or misunderstanding by the caller. For example, a bug like this is documented in #2259. --- diff --git a/lib/cgraph/tokenize.h b/lib/cgraph/tokenize.h index b11010315..a881ad12f 100644 --- a/lib/cgraph/tokenize.h +++ b/lib/cgraph/tokenize.h @@ -46,6 +46,14 @@ static inline tok_t tok(const char *input, const char *separators) { assert(strcmp(separators, "") != 0 && "at least one separator must be provided"); +#ifndef NDEBUG + for (const char *s1 = separators; *s1 != '\0'; ++s1) { + for (const char *s2 = s1 + 1; *s2 != '\0'; ++s2) { + assert(*s1 != *s2 && "duplicate separator characters"); + } + } +#endif + tok_t t = {.start = input, .separators = separators}; // find the end of the first token