From 3124dcdd2c947b0ff601ba11013965f3cf565f65 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 14 Jul 2022 07:58:17 -0700 Subject: [PATCH] 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. --- lib/cgraph/tokenize.h | 8 ++++++++ 1 file changed, 8 insertions(+) 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 -- 2.40.0