Fix wrong result caused by null byte character.

As "len" is the length of the input string plus one strncpy fills the missing character with a null byte. As a result, the string that is used for determining length is too long.

The new version works perfectly fine for me and gives me the right result.