Clarify that RequiredPrefix() "zeroes" its outputs.

Change-Id: I24799d87302165d78eb61544efdcdd04c3d3b9e2
Reviewed-on: https://code-review.googlesource.com/13030
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/re2.cc b/re2/re2.cc
index de63183..fa56026 100644
--- a/re2/re2.cc
+++ b/re2/re2.cc
@@ -200,8 +200,6 @@
     return;
   }
 
-  prefix_.clear();
-  prefix_foldcase_ = false;
   re2::Regexp* suffix;
   if (entire_regexp_->RequiredPrefix(&prefix_, &prefix_foldcase_, &suffix))
     suffix_regexp_ = suffix;
diff --git a/re2/regexp.cc b/re2/regexp.cc
index 712f92d..34209bc 100644
--- a/re2/regexp.cc
+++ b/re2/regexp.cc
@@ -653,7 +653,7 @@
 // with a fixed string prefix.  If so, returns the prefix and
 // the regexp that remains after the prefix.  The prefix might
 // be ASCII case-insensitive.
-bool Regexp::RequiredPrefix(string *prefix, bool *foldcase, Regexp** suffix) {
+bool Regexp::RequiredPrefix(string* prefix, bool* foldcase, Regexp** suffix) {
   // No need for a walker: the regexp must be of the form
   // 1. some number of ^ anchors
   // 2. a literal char or string
diff --git a/re2/regexp.h b/re2/regexp.h
index 4c2be0f..fcc7c0f 100644
--- a/re2/regexp.h
+++ b/re2/regexp.h
@@ -436,7 +436,9 @@
   // begin with a non-empty fixed string (perhaps after ASCII
   // case-folding).  If so, returns the prefix and the sub-regexp that
   // follows it.
-  bool RequiredPrefix(string* prefix, bool *foldcase, Regexp** suffix);
+  // Callers should expect *prefix, *foldcase and *suffix to be "zeroed"
+  // regardless of the return value.
+  bool RequiredPrefix(string* prefix, bool* foldcase, Regexp** suffix);
 
  private:
   // Constructor allocates vectors as appropriate for operator.
diff --git a/re2/testing/required_prefix_test.cc b/re2/testing/required_prefix_test.cc
index d535e87..04a1ee4 100644
--- a/re2/testing/required_prefix_test.cc
+++ b/re2/testing/required_prefix_test.cc
@@ -48,11 +48,13 @@
         flags = flags | Regexp::Latin1;
       Regexp* re = Regexp::Parse(t.regexp, flags, NULL);
       CHECK(re) << " " << t.regexp;
+
       string p;
-      bool f = false;
-      Regexp* s = NULL;
+      bool f;
+      Regexp* s;
       CHECK_EQ(t.return_value, re->RequiredPrefix(&p, &f, &s))
-        << " " << t.regexp << " " << (j==0 ? "latin1" : "utf") << " " << re->Dump();
+        << " " << t.regexp << " " << (j==0 ? "latin1" : "utf")
+        << " " << re->Dump();
       if (t.return_value) {
         CHECK_EQ(p, string(t.prefix))
           << " " << t.regexp << " " << (j==0 ? "latin1" : "utf");