Bug 1534124 - Be more conservative in nsMsgImapLineDownloadCache::SpaceAvailable(). r=mkmelin,benc DONTBUILD
authorJorg K <jorgk@jorgk.com>
Fri, 15 Mar 2019 09:38:10 +0100
changeset 26099 6117debc9c8a0680d8774157147565d46fd45641
parent 26098 36718c82bc319425f064071f0dace4e1bfcc004f
child 26100 f2b728425eaf68a3c61d5f6c749f5400df23dcc5
push id15668
push usermozilla@jorgk.com
push dateFri, 15 Mar 2019 08:38:49 +0000
treeherdercomm-central@6117debc9c8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, benc
bugs1534124
Bug 1534124 - Be more conservative in nsMsgImapLineDownloadCache::SpaceAvailable(). r=mkmelin,benc DONTBUILD
mailnews/base/util/nsMsgLineBuffer.cpp
mailnews/base/util/nsMsgLineBuffer.h
mailnews/imap/src/nsImapProtocol.cpp
mailnews/imap/src/nsImapProtocol.h
--- a/mailnews/base/util/nsMsgLineBuffer.cpp
+++ b/mailnews/base/util/nsMsgLineBuffer.cpp
@@ -264,17 +264,17 @@ nsMsgLineStreamBuffer::nsMsgLineStreamBu
   m_dataBufferSize = aBufferSize;
 }
 
 nsMsgLineStreamBuffer::~nsMsgLineStreamBuffer()
 {
   PR_FREEIF(m_dataBuffer); // release our buffer...
 }
 
-nsresult nsMsgLineStreamBuffer::GrowBuffer(int32_t desiredSize)
+nsresult nsMsgLineStreamBuffer::GrowBuffer(uint32_t desiredSize)
 {
   char* newBuffer = (char *) PR_REALLOC(m_dataBuffer, desiredSize);
   NS_ENSURE_TRUE(newBuffer, NS_ERROR_OUT_OF_MEMORY);
   m_dataBuffer = newBuffer;
   m_dataBufferSize = desiredSize;
   return NS_OK;
 }
 
--- a/mailnews/base/util/nsMsgLineBuffer.h
+++ b/mailnews/base/util/nsMsgLineBuffer.h
@@ -86,17 +86,17 @@ public:
   nsMsgLineStreamBuffer(uint32_t aBufferSize, bool aAllocateNewLines,
                         bool aEatCRLFs = true, char aLineToken = '\n'); // specify the size of the buffer you want the class to use....
 
   // Caller must free the line returned using PR_Free
   // aEndOfLinetoken -- delimiter used to denote the end of a line.
   // aNumBytesInLine -- The number of bytes in the line returned
   // aPauseForMoreData -- There is not enough data in the stream to make a line at this time...
   char * ReadNextLine(nsIInputStream * aInputStream, uint32_t &anumBytesInLine, bool &aPauseForMoreData, nsresult *rv = nullptr, bool addLineTerminator = false);
-  nsresult GrowBuffer(int32_t desiredSize);
+  nsresult GrowBuffer(uint32_t desiredSize);
   void ClearBuffer();
   bool NextLineAvailable();
 private:
   virtual ~nsMsgLineStreamBuffer();
 protected:
   bool m_eatCRLFs;
   bool m_allocateNewLines;
   char * m_dataBuffer;
--- a/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mailnews/imap/src/nsImapProtocol.cpp
@@ -218,17 +218,20 @@ nsMsgImapLineDownloadCache::~nsMsgImapLi
 
 uint32_t nsMsgImapLineDownloadCache::CurrentUID()
 {
     return fLineInfo->uidOfMessage;
 }
 
 uint32_t nsMsgImapLineDownloadCache::SpaceAvailable()
 {
-    return kDownLoadCacheSize - m_bufferPos;
+  MOZ_ASSERT(kDownLoadCacheSize >= m_bufferPos);
+  if (kDownLoadCacheSize <= m_bufferPos)
+    return 0;
+  return kDownLoadCacheSize - m_bufferPos;
 }
 
 msg_line_info *nsMsgImapLineDownloadCache::GetCurrentLineInfo()
 {
   AppendBuffer("", 1); // null terminate the buffer
   fLineInfo->adoptedMessageLine = GetBuffer();
   return fLineInfo;
 }
--- a/mailnews/imap/src/nsImapProtocol.h
+++ b/mailnews/imap/src/nsImapProtocol.h
@@ -49,17 +49,17 @@
 #include "nsSyncRunnableHelpers.h"
 #include "nsICacheEntryOpenCallback.h"
 #include "nsIProtocolProxyCallback.h"
 #include "nsIStringBundle.h"
 
 class nsIMAPMessagePartIDArray;
 class nsIPrefBranch;
 
-#define kDownLoadCacheSize 16000 // was 1536 - try making it bigger
+#define kDownLoadCacheSize 16000u // was 1536 - try making it bigger
 
 
 typedef struct _msg_line_info {
     const char   *adoptedMessageLine;
     uint32_t uidOfMessage;
 } msg_line_info;