Re:New Grad vs. Senior Dev
by ericlippert on Saturday March 28, 2020 @12:06PM
(#22711959)
There is a dereference past the bounds of the query in one case in the last code sample, but there is no deference beyond the bounds of the source string.
You're probably thinking in C# or Java; remember that in C the convention is that a zero char ends strings. If the source string is shorter than the query string then the code will encounter a zero char in the source string at the same time as it encounters a non-zero char in the query string, and the inequality will end the loop before the beyond-bounds dereference.
Re:New Grad vs. Senior Dev
by asib on Sunday March 29, 2020 @03:08PM
(#22721660)
No null checks in find. If source is null, dereferencing source[i] in the while condition will cause undefined behaviour. If just query is null, the same will occur in the first call to starts.
You're probably thinking in C# or Java; remember that in C the convention is that a zero char ends strings. If the source string is shorter than the query string then the code will encounter a zero char in the source string at the same time as it encounters a non-zero char in the query string, and the inequality will end the loop before the beyond-bounds dereference.
There are other defects; can you find them?