lib: fix semantic on has_substring on extreme cases

And avoid illegal access outside the string.

Detected thanks to the interpreted that warns on out-of-bound accesses in nativestrings.