Things like this are called "garbage in, garbage-out" (GIGO). It may be
harmless, or it may hurt you later.
So in this kind of a case, what we are actually dealing with is: garbage in,
principled, correct results out. ;-)
Wouldn't the clean way be to ensure valid strings (only) when they're
built and then make sure that string algorithms (only) preserve
well-formedness of input?
Perhaps this is how the system grew, but it seems to be that it's
yet another legacy of C pointer arithmetic and
about convenience of implementation
rather than a
safety or
performance
issue.
Stephan