Make SkROBuffer::Iter::size() work when exhausted
According to the documentation, this method will return 0 when the Iter is exhausted. Prior to this CL, it crashes instead. Prevent a crash with a null fHead, and add a test to verify the behavior. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1574603002 Review URL: https://codereview.chromium.org/1574603002
This commit is contained in:
parent
0b558cb42c
commit
b512aaa5c8
@ -150,6 +150,9 @@ const void* SkROBuffer::Iter::data() const {
|
||||
}
|
||||
|
||||
size_t SkROBuffer::Iter::size() const {
|
||||
if (!fBlock) {
|
||||
return 0;
|
||||
}
|
||||
return SkTMin(fBlock->fUsed, fRemaining);
|
||||
}
|
||||
|
||||
|
@ -313,3 +313,18 @@ DEF_TEST(RWBuffer, reporter) {
|
||||
delete streams[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that it is safe to call SkROBuffer::Iter::size() when exhausted.
|
||||
DEF_TEST(RWBuffer_size, r) {
|
||||
SkRWBuffer buffer;
|
||||
buffer.append(gABC, 26);
|
||||
|
||||
SkAutoTUnref<SkROBuffer> roBuffer(buffer.newRBufferSnapshot());
|
||||
SkROBuffer::Iter iter(roBuffer);
|
||||
REPORTER_ASSERT(r, iter.data());
|
||||
REPORTER_ASSERT(r, iter.size() == 26);
|
||||
|
||||
// There is only one block in this buffer.
|
||||
REPORTER_ASSERT(r, !iter.next());
|
||||
REPORTER_ASSERT(r, 0 == iter.size());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user