Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Fix Issue 19593 - use memcmp instead of dstrcmp
Browse files Browse the repository at this point in the history
Using dstrcmp inside trace_addsym causes stack overflow, because dmd
 inserts trace_pro function to top of dstrcmp when -profile is added.
  • Loading branch information
kubo39 committed Jan 18, 2019
1 parent c86e4a0 commit 4e75a50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/rt/trace.d
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,10 @@ private Symbol* trace_addsym(Symbol** proot, const(char)[] id)
auto rover = *parent;
while (rover !is null) // while we haven't run out of tree
{
auto cmp = dstrcmp(id, rover.Sident);
immutable len = id.length <= rover.Sident.length ? id.length : rover.Sident.length;
int cmp = memcmp(id.ptr, rover.Sident.ptr, len);
if (!cmp)
cmp = id.length < rover.Sident.length ? -1 : (id.length > rover.Sident.length);
if (cmp == 0)
{
return rover;
Expand Down
1 change: 1 addition & 0 deletions test/profile/mytrace.def.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

FUNCTIONS
_D4core8internal6string__T7dstrcmpZQjFNaNbNiNeMxAaMxQeZi
_Dmain
_D7profile3fooFkZk
4 changes: 4 additions & 0 deletions test/profile/src/profile.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ void main(string[] args)
trace_setdeffilename(args[2]);
foreach (uint i; 0 .. 1_000)
sum += foo(i);

// Issue 19593
assert(!("aaa" >= "bbb"));
assert("aaa" <= "bbb");
}

0 comments on commit 4e75a50

Please sign in to comment.