Skip to content

Commit 6fa7d5d

Browse files
AndrewKraevskiialexrp
authored andcommitted
std.mem: add missing check to lastIndexOfLinear
1 parent c0448a6 commit 6fa7d5d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

lib/std/mem.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize
13961396
/// Consider using `lastIndexOf` instead of this, which will automatically use a
13971397
/// more sophisticated algorithm on larger inputs.
13981398
pub fn lastIndexOfLinear(comptime T: type, haystack: []const T, needle: []const T) ?usize {
1399+
if (needle.len > haystack.len) return null;
13991400
var i: usize = haystack.len - needle.len;
14001401
while (true) : (i -= 1) {
14011402
if (mem.eql(T, haystack[i..][0..needle.len], needle)) return i;

0 commit comments

Comments
 (0)