Fix undefined behavior packing top and left
Shifting a negative signed integer is undefined behavior in
C++11. Convert to unsigned int before packing the word together.
Change-Id: I88251eb753da1bf8887b7f06b3356e828968103a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/657996
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/core/SkGlyph.cpp b/src/core/SkGlyph.cpp
index 4b81077..30a7ea1 100644
--- a/src/core/SkGlyph.cpp
+++ b/src/core/SkGlyph.cpp
@@ -284,7 +284,10 @@
buffer.writeUInt(fID.value());
buffer.writePoint({fAdvanceX, fAdvanceY});
buffer.writeUInt(fWidth << 16 | fHeight);
- buffer.writeUInt(fLeft << 16 | fTop);
+ // Note: << has undefined behavior for negative values.
+ const uint32_t left = fLeft;
+ const uint32_t top = fTop;
+ buffer.writeUInt(left << 16 | top);
buffer.writeUInt(SkTo<uint32_t>(fMaskFormat));
}