Bug 1375400 - Handle single \r line end more gracefully. r=jorgk,aceman
authorqm2k <qm2k@yandex.ru>
Wed, 28 Jun 2017 14:28:17 +0200
changeset 28393 a3698bb735406f58b6de5a525a6e79c3f916d48f
parent 28392 5fa28162667593695c42a6709bc814dbcbc29cf5
child 28394 61ad7098e066d51dd5980c8f110eeb648dcd8d95
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk, aceman
bugs1375400
Bug 1375400 - Handle single \r line end more gracefully. r=jorgk,aceman
mailnews/base/util/nsMsgMailNewsUrl.cpp
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -914,24 +914,19 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
       m_dataBuffer[m_leftOver] = '\0';
 
       start = m_dataBuffer;
       // make sure we don't insert another LF, accidentally, by ignoring
       // second half of CRLF spanning blocks.
       if (lastCharInPrevBuf == '\r' && *start == '\n')
         start++;
 
-      end = PL_strchr(start, '\r');
-      if (!end)
-          end = PL_strchr(start, '\n');
-      else if (*(end+1) == '\n' && linebreak_len == 0)
-          linebreak_len = 2;
-
-      if (linebreak_len == 0) // not initialize yet
-          linebreak_len = 1;
+      end = PL_strpbrk(start, "\r\n");
+      if (end)
+        linebreak_len = (end[0] == '\r' && end[1] == '\n') ? 2 : 1;
 
       count -= readCount;
       maxReadCount = SAVE_BUF_SIZE - m_leftOver;
 
       if (!end && count > maxReadCount)
           // must be a very very long line; sorry cannot handle it
           return NS_ERROR_FAILURE;
 
@@ -950,19 +945,19 @@ NS_IMETHODIMP nsMsgSaveAsListener::OnDat
           }
           start = end+linebreak_len;
           if (start >= m_dataBuffer + m_leftOver)
           {
               maxReadCount = SAVE_BUF_SIZE;
               m_leftOver = 0;
               break;
           }
-          end = PL_strchr(start, '\r');
-          if (!end)
-              end = PL_strchr(start, '\n');
+          end = PL_strpbrk(start, "\r\n");
+          if (end)
+            linebreak_len = (end[0] == '\r' && end[1] == '\n') ? 2 : 1;
           if (start && !end)
           {
               m_leftOver -= (start - m_dataBuffer);
               memcpy(m_dataBuffer, start,
                             m_leftOver+1); // including null
               maxReadCount = SAVE_BUF_SIZE - m_leftOver;
           }
       }