aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-08-10 08:49:03 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-10 08:49:03 -0700
commit4f2b33159b5a5da869ed605abf1d73b5cd429934 (patch)
treea991791bf9345a5128d5f6e2262e727c71710237
parent47dfc36e460356ef624ab90b82921ac6c8cc8e48 (diff)
SkPDF: add assert for that SkWStream behaves.
Motivation: this might catch future issues like this. BUG=skia:4181 Review URL: https://codereview.chromium.org/1287443002
-rw-r--r--src/doc/SkDocument_PDF.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/doc/SkDocument_PDF.cpp b/src/doc/SkDocument_PDF.cpp
index eeb8aa83fd..c1d5f0f461 100644
--- a/src/doc/SkDocument_PDF.cpp
+++ b/src/doc/SkDocument_PDF.cpp
@@ -201,12 +201,16 @@ static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
if (objNumMap.addObject(docCatalog.get())) {
docCatalog->addResources(&objNumMap, substitutes);
}
- size_t baseOffset = SkToOffT(stream->bytesWritten());
+ size_t baseOffset = stream->bytesWritten();
emit_pdf_header(stream);
SkTDArray<int32_t> offsets;
for (int i = 0; i < objNumMap.objects().count(); ++i) {
SkPDFObject* object = objNumMap.objects()[i];
- offsets.push(SkToS32(stream->bytesWritten() - baseOffset));
+ size_t offset = stream->bytesWritten();
+ // This assert checks that size(pdf_header) > 0 and that
+ // the output stream correctly reports bytesWritten().
+ SkASSERT(offset > baseOffset);
+ offsets.push(SkToS32(offset - baseOffset));
SkASSERT(object == substitutes.getSubstitute(object));
SkASSERT(objNumMap.getObjectNumber(object) == i + 1);
stream->writeDecAsText(i + 1);