Bug 786533 - Sprinkle a few -DNOMINMAX and fix uses of std::min with mixed 32/64-bit types. r=ehsan
authorMats Palmgren <matspal@gmail.com>
Mon, 14 Jan 2013 17:51:14 +0100
changeset 14720 50104004f24ddf20dffa537be85c0d4a391a0c74
parent 14719 55c8d994eaeddc3c15cf223847f73c5df9230ea5
child 14721 76eb09d4c8d956814c44812885ff6a2383e7dfeb
push id867
push userbugzilla@standard8.plus.com
push dateMon, 01 Apr 2013 20:44:27 +0000
treeherdercomm-beta@797726b8d244 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs786533
Bug 786533 - Sprinkle a few -DNOMINMAX and fix uses of std::min with mixed 32/64-bit types. r=ehsan
mailnews/addrbook/src/Makefile.in
mailnews/base/util/Makefile.in
mailnews/base/util/nsMsgLineBuffer.cpp
mailnews/base/util/nsMsgProtocol.cpp
mailnews/imap/src/Makefile.in
mailnews/import/eudora/src/Makefile.in
mailnews/import/eudora/src/nsEudoraWin32.cpp
mailnews/import/oexpress/Makefile.in
mailnews/import/text/src/nsTextAddress.cpp
mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
mailnews/news/src/Makefile.in
mailnews/news/src/nsNNTPProtocol.cpp
--- a/mailnews/addrbook/src/Makefile.in
+++ b/mailnews/addrbook/src/Makefile.in
@@ -54,16 +54,17 @@ EXTRA_PP_COMPONENTS += \
 		nsAddrbook.manifest \
 		$(NULL)
 
 EXPORTS		= \
                 nsVCardObj.h \
 		$(NULL)
 
 ifeq ($(OS_ARCH),WINNT)
+OS_CXXFLAGS += -DNOMINMAX
 ifndef GNU_CC
 
 CPPSRCS		+= \
 		nsAbOutlookDirFactory.cpp \
 		nsAbOutlookDirectory.cpp \
 		nsAbWinHelper.cpp \
 		nsMapiAddressBook.cpp \
 		nsWabAddressBook.cpp \
--- a/mailnews/base/util/Makefile.in
+++ b/mailnews/base/util/Makefile.in
@@ -73,12 +73,13 @@ EXTRA_JS_MODULES = \
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 DEFINES		+= -D_IMPL_NS_MSG_BASE
 
 ifeq ($(OS_ARCH),WINNT)
 DEFINES		+= -DZLIB_DLL
+OS_CXXFLAGS	+= -DNOMINMAX
 endif
 
 include $(topsrcdir)/config/rules.mk
 
--- a/mailnews/base/util/nsMsgLineBuffer.cpp
+++ b/mailnews/base/util/nsMsgLineBuffer.cpp
@@ -362,17 +362,17 @@ char * nsMsgLineStreamBuffer::ReadNextLi
         if (NS_FAILED(rv))
           return nullptr;
         startOfLine = m_dataBuffer;
         numFreeBytesInBuffer += growBy;
       }
       NS_ASSERTION(m_startPos == 0, "m_startPos should be 0 .....\n");
     }
     
-    uint32_t numBytesToCopy = std::min(numFreeBytesInBuffer - 1 /* leave one for a null terminator */, numBytesInStream);
+    uint32_t numBytesToCopy = std::min(uint64_t(numFreeBytesInBuffer - 1) /* leave one for a null terminator */, numBytesInStream);
     if (numBytesToCopy > 0)
     {
       // read the data into the end of our data buffer
       char *startOfNewData = startOfLine + m_numBytesInBuffer;
       rv = aInputStream->Read(startOfNewData, numBytesToCopy, &numBytesCopied);
       if (prv)
         *prv = rv;
       uint32_t i;
--- a/mailnews/base/util/nsMsgProtocol.cpp
+++ b/mailnews/base/util/nsMsgProtocol.cpp
@@ -1078,17 +1078,17 @@ public:
           return NS_OK;
         }
         protInst->mSuspendedWrite = false;
 
         uint32_t bytesWritten;
 
         if (avail)
         {
-          rv = aOutStream->WriteFrom(mInStream, std::min(avail, 4096), &bytesWritten);
+          rv = aOutStream->WriteFrom(mInStream, std::min(avail, uint64_t(4096)), &bytesWritten);
           // if were full at the time, the input stream may be backed up and we need to read any remains from the last ODA call
           // before we'll get more ODA calls
           if (protInst->mSuspendedRead)
             protInst->UnblockPostReader();
         }
         else
         {
           rv = aOutStream->Write(protInst->mAsyncBuffer.get(),
@@ -1403,17 +1403,17 @@ nsresult nsMsgAsyncWriteProtocol::Unbloc
   if (mSuspendedRead)
   {
     // (1) attempt to write out any remaining read bytes we need in order to unblock the reader
     if (mSuspendedReadBytes > 0 && mPostDataStream)
     {
       uint64_t avail = 0;
       mPostDataStream->Available(&avail);
 
-      m_outputStream->WriteFrom(mPostDataStream, std::min(avail, mSuspendedReadBytes), &amountWritten);
+      m_outputStream->WriteFrom(mPostDataStream, std::min(avail, uint64_t(mSuspendedReadBytes)), &amountWritten);
       // hmm sometimes my mSuspendedReadBytes is getting out of whack...so for now, reset it
       // if necessary.
       if (mSuspendedReadBytes > avail)
         mSuspendedReadBytes = avail;
 
       if (mSuspendedReadBytes > amountWritten)
         mSuspendedReadBytes -= amountWritten;
       else
--- a/mailnews/imap/src/Makefile.in
+++ b/mailnews/imap/src/Makefile.in
@@ -41,13 +41,17 @@ CPPSRCS		= \
 		nsImapOfflineSync.cpp \
 		nsAutoSyncState.cpp \
 		nsAutoSyncManager.cpp \
 		nsSyncRunnableHelpers.cpp \
 		$(NULL)
 
 include $(topsrcdir)/config/config.mk
 
+ifeq ($(OS_ARCH),WINNT)
+OS_CXXFLAGS += -DNOMINMAX
+endif
+
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
--- a/mailnews/import/eudora/src/Makefile.in
+++ b/mailnews/import/eudora/src/Makefile.in
@@ -26,16 +26,17 @@ CPPSRCS		= \
 		nsEudoraEditor.cpp \
 		nsEudoraCompose.cpp \
 		nsEudoraAddress.cpp \
 		nsEudoraFilters.cpp \
 		$(NULL)
 
 ifeq ($(OS_ARCH),WINNT)
 CPPSRCS += nsEudoraWin32.cpp
+OS_CXXFLAGS += -DNOMINMAX
 endif
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 CPPSRCS += nsEudoraMac.cpp
 endif
 
 LOCAL_INCLUDES += -I$(srcdir)/../../src
 
--- a/mailnews/import/eudora/src/nsEudoraWin32.cpp
+++ b/mailnews/import/eudora/src/nsEudoraWin32.cpp
@@ -198,17 +198,17 @@ nsresult nsEudoraWin32::ScanMailDir(nsIF
     uint64_t bytesLeft64;
     rv = inputStream->Available(&bytesLeft64);
     if (NS_FAILED(rv))
     {
       IMPORT_LOG0("*** Error checking address file for eof\n");
       inputStream->Close();
       return rv;
     }
-    uint32_t bytesLeft = std::min(PR_UINT32_MAX - 1, bytesLeft64);
+    uint32_t bytesLeft = std::min(uint64_t(PR_UINT32_MAX - 1), bytesLeft64);
     pContents = (char *) PR_Malloc(bytesLeft + 1);
     if (!pContents)
       return NS_ERROR_OUT_OF_MEMORY;
     uint32_t bytesRead;
     rv = inputStream->Read(pContents, bytesLeft, &bytesRead);
     if (bytesRead != bytesLeft)
       return NS_ERROR_FAILURE;
     pContents[bytesRead] = '\0';
--- a/mailnews/import/oexpress/Makefile.in
+++ b/mailnews/import/oexpress/Makefile.in
@@ -27,9 +27,13 @@ CPPSRCS		= \
 		nsOE5File.cpp			\
 		nsOESettings.cpp		\
 		nsOEStringBundle.cpp		\
 		$(NULL)
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
+ifeq ($(OS_ARCH),WINNT)
+OS_CXXFLAGS += -DNOMINMAX
+endif
+
 include $(topsrcdir)/config/rules.mk
--- a/mailnews/import/text/src/nsTextAddress.cpp
+++ b/mailnews/import/text/src/nsTextAddress.cpp
@@ -129,17 +129,17 @@ nsresult nsTextAddress::ImportAddresses(
         IMPORT_LOG0("*** Error processing text record.\n");
       }
     }
     if (NS_SUCCEEDED(rv) && pProgress) {
       // This won't be totally accurate, but its the best we can do
       // considering that lineStream won't give us how many bytes
       // are actually left.
       bytesLeft -= line.Length();
-      *pProgress = std::min(totalBytes - bytesLeft, PR_UINT32_MAX);
+      *pProgress = std::min(totalBytes - bytesLeft, uint64_t(PR_UINT32_MAX));
     }
   }
 
   inputStream->Close();
 
   if (NS_FAILED(rv)) {
     IMPORT_LOG0("*** Error reading the address book - probably incorrect ending\n");
     return NS_ERROR_FAILURE;
--- a/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
+++ b/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
@@ -488,17 +488,17 @@ nsMimeBaseEmitter::WriteHelper(const cha
 
   nsresult rv = mOutStream->Write(buf, count, countWritten);
   if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
     // pipe is full, push contents of pipe to listener...
     uint64_t avail;
     rv = mInputStream->Available(&avail);
     if (NS_SUCCEEDED(rv) && avail) {
       mOutListener->OnDataAvailable(mChannel, mURL, mInputStream, 0, 
-                                    std::min(avail, PR_UINT32_MAX));
+                                    std::min(avail, uint64_t(PR_UINT32_MAX)));
 
       // try writing again...
       rv = mOutStream->Write(buf, count, countWritten);
     }
   }
   return rv;
 }
 
@@ -1055,17 +1055,17 @@ nsMimeBaseEmitter::Complete()
   if (mOutListener)
   {
     uint64_t bytesInStream = 0;
     nsresult rv2 = mInputStream->Available(&bytesInStream);
     NS_ASSERTION(NS_SUCCEEDED(rv2), "Available failed");
     if (bytesInStream)
     {
       nsCOMPtr<nsIRequest> request = do_QueryInterface(mChannel);
-      mOutListener->OnDataAvailable(request, mURL, mInputStream, 0, std::min(bytesInStream, PR_UINT32_MAX));
+      mOutListener->OnDataAvailable(request, mURL, mInputStream, 0, std::min(bytesInStream, uint64_t(PR_UINT32_MAX)));
     }
   }
 
   return NS_OK;
 }
 
 //
 // This needs to do the right thing with the stored information. It only
--- a/mailnews/news/src/Makefile.in
+++ b/mailnews/news/src/Makefile.in
@@ -28,13 +28,17 @@ CPPSRCS		= \
 		nsNewsFolder.cpp \
 		nsNntpIncomingServer.cpp \
 		nsNntpMockChannel.cpp \
 		nsNewsUtils.cpp \
 		nsNewsDownloadDialogArgs.cpp \
 		nsNewsDownloader.cpp \
 		$(NULL)
 
+ifeq ($(OS_ARCH),WINNT)
+OS_CXXFLAGS += -DNOMINMAX
+endif
+
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
--- a/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mailnews/news/src/nsNNTPProtocol.cpp
@@ -2113,17 +2113,17 @@ nsresult nsNNTPProtocol::DisplayArticle(
   {
     nsresult rv = NS_OK;
     char *line = m_lineStreamBuffer->ReadNextLine(inputStream, line_length, pauseForMoreData, &rv, true);
     if (pauseForMoreData)
     {
       uint64_t inlength = 0;
       mDisplayInputStream->Available(&inlength);
       if (inlength > 0) // broadcast our batched up ODA changes
-        m_channelListener->OnDataAvailable(this, m_channelContext, mDisplayInputStream, 0, std::min(inlength, PR_UINT32_MAX));
+        m_channelListener->OnDataAvailable(this, m_channelContext, mDisplayInputStream, 0, std::min(inlength, uint64_t(PR_UINT32_MAX)));
       SetFlag(NNTP_PAUSE_FOR_READ);
       PR_Free(line);
       return rv;
     }
 
     if (m_newsFolder)
       m_newsFolder->NotifyDownloadedLine(line, m_key);
 
@@ -2132,17 +2132,17 @@ nsresult nsNNTPProtocol::DisplayArticle(
     {
       m_nextState = NEWS_DONE;
 
       ClearFlag(NNTP_PAUSE_FOR_READ);
 
       uint64_t inlength = 0;
       mDisplayInputStream->Available(&inlength);
       if (inlength > 0) // broadcast our batched up ODA changes
-        m_channelListener->OnDataAvailable(this, m_channelContext, mDisplayInputStream, 0, std::min(inlength, PR_UINT32_MAX));
+        m_channelListener->OnDataAvailable(this, m_channelContext, mDisplayInputStream, 0, std::min(inlength, uint64_t(PR_UINT32_MAX)));
       PR_Free(line);
       return rv;
     }
     else // we aren't finished with the message yet
     {
       uint32_t count = 0;
 
       // skip over the quoted '.'