3 ms·
There are though, when it checks for '\0'. `starts()` looks like it's not checking if len(source) < len(query), but if, say, query="foobar" and source="foo", w
by jpochtar 7y ago
There are though, when it checks for '\0'.
`starts()` looks like it's not checking if len(source) < len(query), but if, say, query="foobar" and source="foo", when i = 3 the line
if (source[i] != query[i])
return false;
will evaluate to
if ('\0' != 'b')
return false;
so `starts()` will correctly return false.
Always if len(source) < len(query), we'll return false when we get to i=len(source), because source[len(source)] != query[len(source)] as source[len(source)] == '\0' and query[len(source)] != '\0' since len(query) > len(source).