diff --git a/base/src/nsString.cpp b/base/src/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/base/src/nsString.cpp +++ b/base/src/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0'; diff --git a/string/obsolete/nsString.cpp b/string/obsolete/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/string/obsolete/nsString.cpp +++ b/string/obsolete/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0'; diff --git a/xpcom/ds/nsString.cpp b/xpcom/ds/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/xpcom/ds/nsString.cpp +++ b/xpcom/ds/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0'; diff --git a/xpcom/string/obsolete/nsString.cpp b/xpcom/string/obsolete/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/xpcom/string/obsolete/nsString.cpp +++ b/xpcom/string/obsolete/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0';