mirror of https://github.com/c-ares/c-ares.git
bug fix: new ares_strsplit (#492)
* add ares_strsplit unit test The test reveals a bug in the implementation of ares_strsplit when the make_set parameter is set to 1, as distinct domains are confused for equal: out = ares_strsplit("example.com, example.co", ", ", 1, &n); evaluates to n = 1 with out = { "example.com" }. * bugfix and cleanup of ares_strsplit The purpose of ares_strsplit in c-ares is to split a comma-delimited string of unique (up to letter case) domains. However, because the terminating NUL byte was not checked in the substrings when comparing for uniqueness, the function would sometimes drop domains it should not. For example, ares_strsplit("example.com, example.co", ",") would only result in a single domain "example.com". Aside from this bugfix, the following cleanup is performed: 1. The tokenization now happens with the help of strcspn instead of the custom function is_delim. 2. The function list_contains has been inlined. 3. The interface of ares_strsplit has been simplified by removing the parameter make_set since in practice it was always 1. 4. There are fewer passes over the input string. 5. We resize the table using realloc() down to its minimum size. 6. The docstring of ares_strsplit is updated and also a couple typos are fixed. There occurs a single use of ares_strsplit and since the make_set parameter has been removed, the call in ares_init.c is modified accordingly. The unit test for ares_strsplit is also updated. Fix By: Nikolaos Chatzikonstantinou (@createyourpersonalaccount)pull/495/head^2
parent
4b7301a0d2
commit
313bd2aa7e
4 changed files with 98 additions and 135 deletions
Loading…
Reference in new issue