Bug 851981: Make loop iterator in mozalloc_handle_oom a size_t instead of an int, to fix build warning for signed/unsigned comparison. r=bsmedberg
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 18 Mar 2013 10:58:31 -0700
changeset 125273 8696e05237729bb008c8484f8b717647fcfd6897
parent 125272 e8909e54a20d513341612559ebfdaf96f1a59f1c
child 125274 bdfac277d15ffa6d67242b334fc86e4515888210
push id24450
push userryanvm@gmail.com
push dateTue, 19 Mar 2013 13:43:35 +0000
treeherdermozilla-central@2c41bf87b4e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs851981
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 851981: Make loop iterator in mozalloc_handle_oom a size_t instead of an int, to fix build warning for signed/unsigned comparison. r=bsmedberg
memory/mozalloc/mozalloc_oom.cpp
--- a/memory/mozalloc/mozalloc_oom.cpp
+++ b/memory/mozalloc/mozalloc_oom.cpp
@@ -6,41 +6,45 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if defined(XP_WIN) || defined(XP_OS2)
 #  define MOZALLOC_EXPORT __declspec(dllexport)
 #endif
 
 #include "mozilla/mozalloc_abort.h"
 #include "mozilla/mozalloc_oom.h"
+#include "mozilla/Assertions.h"
 
 static mozalloc_oom_abort_handler gAbortHandler;
 
 #define OOM_MSG_LEADER "out of memory: 0x"
 #define OOM_MSG_DIGITS "0000000000000000" // large enough for 2^64
 #define OOM_MSG_TRAILER " bytes requested"
 #define OOM_MSG_FIRST_DIGIT_OFFSET sizeof(OOM_MSG_LEADER) - 1
 #define OOM_MSG_LAST_DIGIT_OFFSET sizeof(OOM_MSG_LEADER) + \
                                   sizeof(OOM_MSG_DIGITS) - 3
 
 static const char *hex = "0123456789ABCDEF";
 
 void
 mozalloc_handle_oom(size_t size)
 {
     char oomMsg[] = OOM_MSG_LEADER OOM_MSG_DIGITS OOM_MSG_TRAILER;
-    int i;
+    size_t i;
 
     // NB: this is handle_oom() stage 1, which simply aborts on OOM.
     // we might proceed to a stage 2 in which an attempt is made to
     // reclaim memory
 
     if (gAbortHandler)
         gAbortHandler(size);
 
+    MOZ_STATIC_ASSERT(OOM_MSG_FIRST_DIGIT_OFFSET > 0,
+                      "Loop below will never terminate (i can't go below 0)");
+
     // Insert size into the diagnostic message using only primitive operations
     for (i = OOM_MSG_LAST_DIGIT_OFFSET;
          size && i >= OOM_MSG_FIRST_DIGIT_OFFSET; i--) {
       oomMsg[i] = hex[size % 16];
       size /= 16;
     }
 
     mozalloc_abort(oomMsg);