Skip to content

Commit

Permalink
[my_runtime_test] Fix bug caught on continuous build.
Browse files Browse the repository at this point in the history
Why didn't this happen on my own machine?

http://travis-ci.oilshell.org/srht-jobs/2021-02-06__19-34-07.wwz/_tmp/toil/logs/cpp-unit-all.txt

--> COLLECT with 0 roots
i = -2147483648
.AddressSanitizer:DEADLYSIGNAL
=================================================================
==3052==ERROR: AddressSanitizer: SEGV on unknown address 0x7f8666c53034 (pc 0x55618e7f6d5b bp 0x7ffc429f1190 sp 0x7ffc429f1180 T0)
==3052==The signal is caused by a READ memory access.
    #0 0x55618e7f6d5a in gc_heap::str_equals(gc_heap::Str*, gc_heap::Str*) /home/build/oil/mycpp/gc_heap.cc:260
    #1 0x55618e7dafd0 in str_replace_test /home/build/oil/mycpp/my_runtime_test.cc:162
    #2 0x55618e7e7bd6 in main /home/build/oil/mycpp/my_runtime_test.cc:779
    #3 0x7f866924109a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
    #4 0x55618e7d94b9 in _start (/home/build/oil/mycpp/_bin/my_runtime_test.asan+0xd4b9)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/build/oil/mycpp/gc_heap.cc:260 in gc_heap::str_equals(gc_heap::Str*, gc_heap::Str*)
  • Loading branch information
Andy Chu committed Feb 6, 2021
1 parent 0080e75 commit ca5de9e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mycpp/my_runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,32 @@ TEST str_replace_test() {
Str* _123 = nullptr;
Str* s = nullptr;
Str* foxo = nullptr;
StackRoots _roots({&o, &_12, &_123, &s, &foxo});
Str* expected = nullptr;
StackRoots _roots({&o, &_12, &_123, &s, &foxo, &expected});

o = NewStr("o");
_12 = NewStr("12");
_123 = NewStr("123");

s = kStrFood->replace(o, _12);
ASSERT(str_equals(NewStr("f1212d"), s));
ASSERT(str_equals0("f1212d", s));
print(s);

s = kStrFoo->replace(o, _123);
ASSERT(str_equals(NewStr("f123123"), s));
ASSERT(str_equals0("f123123", s));
print(s);

foxo = NewStr("foxo");
s = foxo->replace(o, _123);
ASSERT(str_equals(NewStr("f123x123"), s));
ASSERT(str_equals0("f123x123", s));
print(s);

s = kWithNull->replace(a, XX);
print(s);

// Explicit length because of \0
ASSERT(str_equals(NewStr("foo\0bXXr", 8), s));
expected = NewStr("foo\0bXXr", 8);
ASSERT(str_equals(expected, s));

PASS();
}
Expand Down

0 comments on commit ca5de9e

Please sign in to comment.