Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Unified Diff: src/core/SkWriter32.cpp

Issue 130913018: Templetized SkWriter32 readTAt() & overwriteTAt() (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: readTAt()/overwriteTAt() only Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkWriter32.cpp
diff --git a/src/core/SkWriter32.cpp b/src/core/SkWriter32.cpp
index 5e89ed655b70e5d83da4df2588704689898b52e6..cb8506882780a7df172f6af71cc01ba2c0c7115a 100644
--- a/src/core/SkWriter32.cpp
+++ b/src/core/SkWriter32.cpp
@@ -44,15 +44,19 @@ void SkWriter32::writeString(const char str[], size_t len) {
if ((long)len < 0) {
len = strlen(str);
}
- this->write32(len);
+
// add 1 since we also write a terminating 0
mtklein 2014/02/10 22:37:34 Hmm, maybe we can make this clearer? Does this wo
f(malita) 2014/02/11 03:30:56 Ah, reservePad takes care of padding, doesn't it.
size_t alignedLen = SkAlign4(len + 1);
- char* ptr = (char*)this->reserve(alignedLen);
+ // reserve an additional 4 bytes for len storage
+ uint32_t* lenPtr = this->reserve(alignedLen + sizeof(uint32_t));
+ char* ptr = (char*)(lenPtr + 1);
{
// Write the terminating 0 and fill in the rest with zeroes
uint32_t* padding = (uint32_t*)(ptr + (alignedLen - 4));
*padding = 0;
}
+
+ *lenPtr = len;
// Copy the string itself.
memcpy(ptr, str, len);
}

Powered by Google App Engine
This is Rietveld 408576698