Skip to content

Commit 40bae5d

Browse files
authored
Merge pull request #5034 from LemonBoy/correct-cast
Cast a void pointer to char* before subtracting it
2 parents 088a998 + ccfd300 commit 40bae5d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

std/algorithm/searching.d

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ if (isInputRange!InputRange &&
14161416
import core.stdc.string : memchr;
14171417
auto ptr = memchr(haystack.ptr, needle, haystack.length);
14181418
return ptr ?
1419-
haystack[ptr - haystack.ptr .. $] :
1419+
haystack[cast(char*)ptr - haystack.ptr .. $] :
14201420
haystack[$ .. $];
14211421
}
14221422
return trustedMemchr(haystack, needle);
@@ -1593,10 +1593,13 @@ if (isInputRange!InputRange &&
15931593
E e2 = 'c';
15941594
assert(find ("日c語", 'c') == "c語");
15951595
assert(find!((a,b)=>a==b)("日c語", 'c') == "c語");
1596+
R r3 = "0123456789";
1597+
E e3 = 'A';
1598+
assert(find ("0123456789", 'A').empty);
15961599
static if (E.sizeof >= 2)
15971600
{
1598-
R r3 = "hello world";
1599-
E e3 = 'w';
1601+
R r4 = "hello world";
1602+
E e4 = 'w';
16001603
assert(find ("日本語", '') == "本語");
16011604
assert(find!((a,b)=>a==b)("日本語", '') == "本語");
16021605
}

0 commit comments

Comments
 (0)