Bug 1410617 - compare uint64_t with size_t only on 32bit platforms. r?valentin draft
authorSylvestre Ledru <sledru@mozilla.com>
Sat, 21 Oct 2017 14:07:08 +0200
changeset 684367 1bd4822983fa6a20eea9e56b42e104f9a4a8128c
parent 684366 d697979497a6196b62ed15879e799c2c0cb1f25c
child 684368 044f8458c6f6b784476e36625b78bdc06c73c120
push id85595
push userbmo:sledru@mozilla.com
push dateSat, 21 Oct 2017 12:08:42 +0000
reviewersvalentin
bugs1410617
milestone58.0a1
Bug 1410617 - compare uint64_t with size_t only on 32bit platforms. r?valentin MozReview-Commit-ID: GR4lQhyDUJe
netwerk/base/nsStreamLoader.cpp
--- a/netwerk/base/nsStreamLoader.cpp
+++ b/netwerk/base/nsStreamLoader.cpp
@@ -68,17 +68,21 @@ nsStreamLoader::GetRequest(nsIRequest **
 NS_IMETHODIMP
 nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
 {
   nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
   if (chan) {
     int64_t contentLength = -1;
     chan->GetContentLength(&contentLength);
     if (contentLength >= 0) {
-      if (uint64_t(contentLength) > std::numeric_limits<size_t>::max()) {
+      // On 64bit platforms size of uint64_t coincides with the size of size_t,
+      // so we want to compare with the minimum from size_t and int64_t.
+      if (static_cast<uint64_t>(contentLength) >
+          std::min(std::numeric_limits<size_t>::max(),
+                   static_cast<size_t>(std::numeric_limits<int64_t>::max()))) {
         // Too big to fit into size_t, so let's bail.
         return NS_ERROR_OUT_OF_MEMORY;
       }
       // preallocate buffer
       if (!mData.initCapacity(contentLength)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
     }