Fix string assert and dead code which caused it.
authorbungeman <bungeman@google.com>
Mon, 11 Aug 2014 14:19:56 +0000 (07:19 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 11 Aug 2014 14:19:57 +0000 (07:19 -0700)
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

src/core/SkString.cpp
tools/flags/SkCommandLineFlags.cpp

index ba1da4136893dffcbc5e1ac8252d9e3a4118a977..1e29dc71723bdb803e5d2d9cd7c9ac68be3fe55d 100644 (file)
@@ -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);
index 42e9ebd971da2d59120b4a9b8f85e83b643c0c9a..c25fec5343cb04f2b3744c248b163a314090b80e 100644 (file)
@@ -287,10 +287,6 @@ void SkCommandLineFlags::Parse(int argc, char** argv) {
                 flag = flag->next();
             }
             if (!flagMatched) {
-                SkString stripped(argv[i]);
-                while (stripped.startsWith('-')) {
-                    stripped.remove(0, 1);
-                }
                 if (!FLAGS_undefok) {
                     SkDebugf("Got unknown flag \"%s\". Exiting.\n", argv[i]);
                     exit(-1);