Bug 1305422 - part 12 - don't call size_forward in {Body,Fetch}Util.cpp; r=bkelly
authorNathan Froyd <froydnj@mozilla.com>
Thu, 29 Sep 2016 22:33:57 -0400
changeset 315883 17a8607397e55ea4ea383beddc8969e0f5b78511
parent 315882 088bfcd8f3cb583e0357c73b8ce03b8bea95df3d
child 315884 b26623101a0d921ea19d27e85c5262aab1313d8e
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1305422
milestone52.0a1
Bug 1305422 - part 12 - don't call size_forward in {Body,Fetch}Util.cpp; r=bkelly
dom/base/BodyUtil.cpp
dom/fetch/FetchUtil.cpp
--- a/dom/base/BodyUtil.cpp
+++ b/dom/base/BodyUtil.cpp
@@ -75,19 +75,20 @@ public:
   GetText()
   {
     return mDecoded;
   }
 };
 
 // Reads over a CRLF and positions start after it.
 static bool
-PushOverLine(nsACString::const_iterator& aStart)
+PushOverLine(nsACString::const_iterator& aStart,
+	     const nsACString::const_iterator& aEnd)
 {
-  if (*aStart == nsCRT::CR && (aStart.size_forward() > 1) && *(++aStart) == nsCRT::LF) {
+  if (*aStart == nsCRT::CR && (aEnd - aStart > 1) && *(++aStart) == nsCRT::LF) {
     ++aStart; // advance to after CRLF
     return true;
   }
 
   return false;
 }
 
 class MOZ_STACK_CLASS FillFormIterator final
@@ -389,29 +390,29 @@ public:
           if (start != end && *start == '-') {
             // End of data.
             if (!mFormData) {
               mFormData = new FormData();
             }
             return true;
           }
 
-          if (!PushOverLine(start)) {
+          if (!PushOverLine(start, end)) {
             return false;
           }
           mState = PARSE_HEADER;
           break;
 
         case PARSE_HEADER:
           bool emptyHeader;
           if (!ParseHeader(start, end, &emptyHeader)) {
             return false;
           }
 
-          if (emptyHeader && !PushOverLine(start)) {
+          if (emptyHeader && !PushOverLine(start, end)) {
             return false;
           }
 
           mState = emptyHeader ? PARSE_BODY : PARSE_HEADER;
           break;
 
         case PARSE_BODY:
           if (mName.IsVoid()) {
--- a/dom/fetch/FetchUtil.cpp
+++ b/dom/fetch/FetchUtil.cpp
@@ -46,19 +46,20 @@ FindCRLF(nsACString::const_iterator& aSt
          nsACString::const_iterator& aEnd)
 {
   nsACString::const_iterator end(aEnd);
   return FindInReadable(NS_LITERAL_CSTRING("\r\n"), aStart, end);
 }
 
 // Reads over a CRLF and positions start after it.
 static bool
-PushOverLine(nsACString::const_iterator& aStart)
+PushOverLine(nsACString::const_iterator& aStart,
+	     const nsACString::const_iterator& aEnd)
 {
-  if (*aStart == nsCRT::CR && (aStart.size_forward() > 1) && *(++aStart) == nsCRT::LF) {
+  if (*aStart == nsCRT::CR && (aEnd - aStart > 1) && *(++aStart) == nsCRT::LF) {
     ++aStart; // advance to after CRLF
     return true;
   }
 
   return false;
 }
 
 // static
@@ -81,32 +82,33 @@ FetchUtil::ExtractHeader(nsACString::con
 
   if (aStart.get() == beginning) {
     *aWasEmptyHeader = true;
     return true;
   }
 
   nsAutoCString header(beginning, aStart.get() - beginning);
 
-  nsACString::const_iterator headerStart, headerEnd;
+  nsACString::const_iterator headerStart, iter, headerEnd;
   header.BeginReading(headerStart);
   header.EndReading(headerEnd);
-  if (!FindCharInReadable(':', headerStart, headerEnd)) {
+  iter = headerStart;
+  if (!FindCharInReadable(':', iter, headerEnd)) {
     return false;
   }
 
-  aHeaderName.Assign(StringHead(header, headerStart.size_backward()));
+  aHeaderName.Assign(StringHead(header, iter - headerStart));
   aHeaderName.CompressWhitespace();
   if (!NS_IsValidHTTPToken(aHeaderName)) {
     return false;
   }
 
-  aHeaderValue.Assign(Substring(++headerStart, headerEnd));
+  aHeaderValue.Assign(Substring(++iter, headerEnd));
   if (!NS_IsReasonableHTTPHeaderValue(aHeaderValue)) {
     return false;
   }
   aHeaderValue.CompressWhitespace();
 
-  return PushOverLine(aStart);
+  return PushOverLine(aStart, aEnd);
 }
 
 } // namespace dom
 } // namespace mozilla