2009-05-07  Farid Zaripov  <faridz@apache.org>

	Merged revs 771735, 771736, 771743 from 4.2.x branch.

	2009-05-05  Farid Zaripov  <faridz@apache.org>
	* tests/regress/21.string.find.stdcxx-1035.cpp: New regression
	test for STDCXX-1035.

	2009-05-05  Farid Zaripov  <faridz@apache.org>
	* tests/strings/21.string.find.cpp: Added new testcases
	to verify bug, described in STDCXX-1035 issue.

	2009-05-05  Farid Zaripov  <faridz@apache.org>
	STDCXX-1035
	* include/string.cc (find): Initialize __first only on the first
	occurrence of the first element of the sought sequence. Look for
	the first occurrence of the first element of the sought sequence,
	starting from the last compared character in controlling sequence.


git-svn-id: https://svn.apache.org/repos/asf/stdcxx/trunk@772572 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/include/string.cc b/include/string.cc
index c6325fb..7b4d2b0 100644
--- a/include/string.cc
+++ b/include/string.cc
@@ -722,15 +722,15 @@
                 return size_type (__next - _C_data);
 
             if (traits_type::eq (*__n, *__s)) {
-                if (__next != __first && traits_type::eq (*__n, *__seq))
-                    __first = __n + 1;
+                if (const_pointer () == __first && __n != __next && traits_type::eq (*__n, *__seq))
+                    __first = __n;
             }
             else {
                 if (const_pointer () == __first) {
                     // look for the first occurrence of the first element
                     // of the sought sequence in the rest of the cotrolling
                     // sequence
-                    __first = traits_type::find (__next + 1, __ext - 1, *__seq);
+                    __first = traits_type::find (__n, __end - __n, *__seq);
 
                     if (const_pointer () == __first)
                         return npos;
diff --git a/tests/regress/21.string.find.stdcxx-1035.cpp b/tests/regress/21.string.find.stdcxx-1035.cpp
new file mode 100644
index 0000000..34a9bb4
--- /dev/null
+++ b/tests/regress/21.string.find.stdcxx-1035.cpp
@@ -0,0 +1,42 @@
+/************************************************************************
+*
+* 21.string.find.stdcxx-1035.cpp - regression test for STDCXX-1035
+*
+* https://issues.apache.org/jira/browse/STDCXX-1035
+*
+* $Id$
+*
+***************************************************************************
+*
+* Licensed to the Apache Software  Foundation (ASF) under one or more
+* contributor  license agreements.  See  the NOTICE  file distributed
+* with  this  work  for  additional information  regarding  copyright
+* ownership.   The ASF  licenses this  file to  you under  the Apache
+* License, Version  2.0 (the  "License"); you may  not use  this file
+* except in  compliance with the License.   You may obtain  a copy of
+* the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the  License is distributed on an  "AS IS" BASIS,
+* WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+* implied.   See  the License  for  the  specific language  governing
+* permissions and limitations under the License.
+*
+**************************************************************************/
+
+#include <cassert>
+#include <string>
+
+int main ()
+{
+    std::string s = ".google.com";
+    std::string s1 = "www.google.google.com";
+
+    std::string::size_type pos = s1.find (s);
+
+    assert(10 == pos);
+
+    return 0;
+}
diff --git a/tests/strings/21.string.find.cpp b/tests/strings/21.string.find.cpp
index a51cc93..acb1587 100644
--- a/tests/strings/21.string.find.cpp
+++ b/tests/strings/21.string.find.cpp
@@ -91,6 +91,7 @@
     TEST ("edfcbahjig", "cba",           3),
     TEST ("edfcbahcba", "cba",           3),
     TEST ("cbacbahjig", "cba",           0),
+    TEST ("abcbcbd",    "bcbd",          3),
 
     TEST ("e\0cb\0\0g", "b\0\0g",        3),
     TEST ("e\0cb\0\0g", "ecb",        NPOS),
@@ -173,6 +174,7 @@
     TEST ("edfcbahjig", "cba",           3),
     TEST ("edfcbahcba", "cba",           3),
     TEST ("cbacbahjig", "cba",           0),
+    TEST ("abcbcbd",    "bcbd",          3),
 
     TEST ("e\0cb\0\0g", "b\0\0g",        3),
     TEST ("e\0cb\0\0g", "ecb",        NPOS),
@@ -262,6 +264,7 @@
     TEST ("edfcbahcba", "cba",         1,     3),
     TEST ("edfcbahcba", "cba",         5,     7),
     TEST ("cbacbahjig", "cba",         5,  NPOS),
+    TEST ("abcbcbd",    "bcbd",        0,     3),
 
     TEST ("e\0cb\0\0g", "b\0\0g",      0,     3),
     TEST ("e\0cb\0\0g", "b\0\0g",      4,  NPOS),
@@ -367,6 +370,7 @@
     TEST ("edfcbahcba", "cba",         5,  3,    7),
     TEST ("cbacbahjig", "cba",         5,  3, NPOS),
     TEST ("cbacbahjcg", "cba",         5,  1,    8),
+    TEST ("abcbcbd",    "bcbd",        0,  4,    3),
 
     TEST ("e\0cb\0\0g", "b\0\0g",      0,  4,    3),
     TEST ("e\0cb\0\0g", "b\0\0g",      4,  4, NPOS),
@@ -484,6 +488,7 @@
     TEST ("edfcbahcba", "cba",         1,    3),
     TEST ("edfcbahcba", "cba",         5,    7),
     TEST ("cbacbahjig", "cba",         5, NPOS),
+    TEST ("abcbcbd",    "bcbd",        0,    3),
 
     TEST ("e\0cb\0\0g", "b\0\0g",      0,    3),
     TEST ("e\0cb\0\0g", "b\0\0g",      4, NPOS),