Skip to content

Add NulTerminatedInclusive iterator, rewrite/fix strchr/wcschr

Peter Limkilde Svendsen requested to merge plimkilde/relibc:strchr-iter into master

This is a rewrite of strchr() and wcschr() to use iterators.

The previous implementation of strchr() was incorrect, as it did not properly return the position of the terminating nul if searched for. (Both strchr and wcschr are explicitly specified to consider the terminating nul part of the string.) The corresponding test has been fixed, and now matches glibc output.

There was no test for wcschr(), so one has been added here.

To achieve this new implementation, a NulTerminatedInclusive iterator has been added. This is essentially the initial implementation of NulTerminated that was rejected in !507 (merged), but including a pointer or reference to the terminating nul is necessary in order to implement these two functions correctly.

Merge request reports