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

Unified Diff: src/core/SkString.cpp

Issue 453333002: Fix string assert and dead code which caused it. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Clarify asserts, avoid potential overflow. Created 6 years, 4 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
« no previous file with comments | « no previous file | tools/flags/SkCommandLineFlags.cpp » ('j') | 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 ba1da4136893dffcbc5e1ac8252d9e3a4118a977..1e29dc71723bdb803e5d2d9cd7c9ac68be3fe55d 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);
« no previous file with comments | « no previous file | tools/flags/SkCommandLineFlags.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698