aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-11-05 11:35:21 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-05 11:35:21 -0800
commit225fb98e1e321fa80e3457fafcd5d1fa14d9f8c3 (patch)
treebdf0eb60b73d3269dce3e38c4aa0288e0e671f8f /src
parent76c4fa6e300d08fb1a17cc446735710f2233e15c (diff)
Avoid dec = -dec overflow when appending most negative signed integers.
Diffstat (limited to 'src')
-rw-r--r--src/core/SkString.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index d3a28e248b..b43351599f 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) {