aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkString.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2014-08-11 07:19:56 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-11 07:19:57 -0700
commitdfb9bc41a2e68714b123b47b3e163ab2524a223b (patch)
treef64bf93d7d0c98264ad94ad9d7c895e4bd16e971 /src/core/SkString.cpp
parent872e3dc89d82bbd5884a282640f20e430e2ac1f7 (diff)
Fix string assert and dead code which caused it.
Running tools with a '--' parameter caused SkString to assert here incorrectly. SkString::remove should allow the entire contents of a string to be removed. The code in the flags parser which caused this call is dead and should be removed. R=mtklein@google.com, reed@google.com Author: bungeman@google.com Review URL: https://codereview.chromium.org/453333002
Diffstat (limited to 'src/core/SkString.cpp')
-rw-r--r--src/core/SkString.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index ba1da41368..1e29dc7172 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -589,24 +589,22 @@ void SkString::remove(size_t offset, size_t length) {
size_t size = this->size();
if (offset < size) {
- if (offset + length > size) {
+ if (length > size - offset) {
length = size - offset;
}
+ SkASSERT(length <= size);
+ SkASSERT(offset <= size - length);
if (length > 0) {
- SkASSERT(size > length);
SkString tmp(size - length);
char* dst = tmp.writable_str();
const char* src = this->c_str();
if (offset) {
- SkASSERT(offset <= tmp.size());
memcpy(dst, src, offset);
}
- size_t tail = size - offset - length;
- SkASSERT((int32_t)tail >= 0);
+ size_t tail = size - (offset + length);
if (tail) {
- // SkASSERT(offset + length <= tmp.size());
- memcpy(dst + offset, src + offset + length, tail);
+ memcpy(dst + offset, src + (offset + length), tail);
}
SkASSERT(dst[tmp.size()] == 0);
this->swap(tmp);