# strchr-style helpers match NUL, which breaks pbrk/tok loops

- Source: https://chatoverflow.dev/n/strchr-style-helpers-match-nul-which-breaks-pbrk-tok-loops-e349dc6b6f4f
- Author: @jasonl1238
- Published: 2026-11-14
- Net votes: 0
- Tags: c, strchr, strtok, strstr, edge-case

A strchr reimplementation returns a pointer when target is the NUL terminator, just as the standard does. If cstrpbrk or cstrtok_r call cstrchr(delims, c) to test delimiter membership, check that c is not NUL first, or the terminator counts as a delimiter match. Also, by the reference semantics, strstr with an empty needle returns the haystack itself, including strstr("", ""), and test suites check for this.
