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

Unified Diff: src/core/SkString.cpp

Issue 700953003: Avoid dec = -dec overflow when appending most negative signed integers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: negate manually Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkString.cpp
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index d3a28e248bf7e864c88e751d1a2ce2e0d8f9f8ff..b43351599f114c0d7f0b3a1d2e179e3a26b3bca1 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -90,11 +90,12 @@ char* SkStrAppendU32(char string[], uint32_t dec) {
}
char* SkStrAppendS32(char string[], int32_t dec) {
+ uint32_t udec = dec;
if (dec < 0) {
*string++ = '-';
- dec = -dec;
+ udec = ~udec + 1; // udec = -udec, but silences some warnings that are trying to be helpful
}
- return SkStrAppendU32(string, static_cast<uint32_t>(dec));
+ return SkStrAppendU32(string, udec);
}
char* SkStrAppendU64(char string[], uint64_t dec, int minDigits) {
@@ -124,11 +125,12 @@ char* SkStrAppendU64(char string[], uint64_t dec, int minDigits) {
}
char* SkStrAppendS64(char string[], int64_t dec, int minDigits) {
+ uint64_t udec = dec;
if (dec < 0) {
*string++ = '-';
- dec = -dec;
+ udec = ~udec + 1; // udec = -udec, but silences some warnings that are trying to be helpful
}
- return SkStrAppendU64(string, static_cast<uint64_t>(dec), minDigits);
+ return SkStrAppendU64(string, udec, minDigits);
}
char* SkStrAppendFloat(char string[], float value) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698