Skip to content

Commit

Permalink
Fix bug in runtime test for installCommonValueWitnesses_pod_indirect.
Browse files Browse the repository at this point in the history
It didn't properly set "withInlineStorage(false)" on the test value witness table, causing it to pick direct-storage value witnesses that overflow a fixed-size buffer and crash on the ASan bot. Fix the test, and add a check for a canary that fails even without ASan.

Swift SVN r30462
  • Loading branch information
jckarter committed Jul 21, 2015
1 parent aa3b870 commit 6f47a4a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions unittests/runtime/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,8 @@ TEST(MetadataTest, installCommonValueWitnesses_pod_indirect) {
testTable.flags = ValueWitnessFlags()
.withAlignment(alignof(ValueBuffer))
.withPOD(true)
.withBitwiseTakable(true);
.withBitwiseTakable(true)
.withInlineStorage(false);
testTable.stride = sizeof(ValueBuffer) + alignof(ValueBuffer);

installCommonValueWitnesses(&testTable);
Expand All @@ -749,11 +750,16 @@ TEST(MetadataTest, installCommonValueWitnesses_pod_indirect) {

free(mem);
};

ValueBuffer buf1, buf2;
testTable.allocateBuffer(&buf1, &testMetadata);
testTable.initializeBufferWithTakeOfBuffer(&buf2, &buf1, &testMetadata);
testTable.destroyBuffer(&buf2, &testMetadata);
struct {
ValueBuffer buffer;
uintptr_t canary;
} buf1{{}, {0x5A5A5A5AU}}, buf2{{}, {0xA5A5A5A5U}};
testTable.allocateBuffer(&buf1.buffer, &testMetadata);
testTable.initializeBufferWithTakeOfBuffer(&buf2.buffer, &buf1.buffer,
&testMetadata);
testTable.destroyBuffer(&buf2.buffer, &testMetadata);

EXPECT_EQ(AllocatedBuffer, DeallocatedBuffer);
EXPECT_EQ(buf1.canary, (uintptr_t)0x5A5A5A5AU);
EXPECT_EQ(buf2.canary, (uintptr_t)0xA5A5A5A5U);
}

0 comments on commit 6f47a4a

Please sign in to comment.