lib: fix semantic on has_substring on extreme cases

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