Bug 1302401 - Finds integer literals which are cast to bool. draft
authorSylvestre Ledru <sylvestre@debian.org>
Tue, 13 Sep 2016 14:22:49 +0200
changeset 417991 2a31f8aa21d956ee75d9292b320b2ee2332b3357
parent 417914 66a77b9bfe5dcacd50eccf85de7c0e7e15ce0ffd
child 417992 02d99d2c6ffef74c31114fd336defa0b1063dccb
child 417995 3e7cf96f87d5cc7a9a43d4e1790457c5382be8f1
push id30553
push userbmo:sledru@mozilla.com
push dateTue, 27 Sep 2016 13:22:39 +0000
bugs1302401
milestone52.0a1
Bug 1302401 - Finds integer literals which are cast to bool. MozReview-Commit-ID: DkzKx4FnVTV
js/src/ctypes/CTypes.cpp
js/src/frontend/ParseNode.h
js/src/vm/TraceLoggingGraph.cpp
--- a/js/src/ctypes/CTypes.cpp
+++ b/js/src/ctypes/CTypes.cpp
@@ -3898,17 +3898,17 @@ BuildTypeName(JSContext* cx, JSObject* t
 
   // Walk the hierarchy of types, outermost to innermost, building up the type
   // string. This consists of the base type, which goes on the left.
   // Derived type modifiers (* and []) build from the inside outward, with
   // pointers on the left and arrays on the right. An excellent description
   // of the rules for building C type declarations can be found at:
   // http://unixwiz.net/techtips/reading-cdecl.html
   TypeCode prevGrouping = CType::GetTypeCode(typeObj), currentGrouping;
-  while (1) {
+  while (true) {
     currentGrouping = CType::GetTypeCode(typeObj);
     switch (currentGrouping) {
     case TYPE_pointer: {
       // Pointer types go on the left.
       PrependString(result, "*");
 
       typeObj = PointerType::GetBaseType(typeObj);
       prevGrouping = currentGrouping;
--- a/js/src/frontend/ParseNode.h
+++ b/js/src/frontend/ParseNode.h
@@ -447,29 +447,29 @@ class ParseNode
     ParseNode(const ParseNode& other) = delete;
     void operator=(const ParseNode& other) = delete;
 
   public:
     ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity)
       : pn_type(kind),
         pn_op(op),
         pn_arity(arity),
-        pn_parens(0),
+        pn_parens(false),
         pn_pos(0, 0),
         pn_next(nullptr)
     {
         MOZ_ASSERT(kind < PNK_LIMIT);
         memset(&pn_u, 0, sizeof pn_u);
     }
 
     ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity, const TokenPos& pos)
       : pn_type(kind),
         pn_op(op),
         pn_arity(arity),
-        pn_parens(0),
+        pn_parens(false),
         pn_pos(pos),
         pn_next(nullptr)
     {
         MOZ_ASSERT(kind < PNK_LIMIT);
         memset(&pn_u, 0, sizeof pn_u);
     }
 
     JSOp getOp() const                     { return JSOp(pn_op); }
--- a/js/src/vm/TraceLoggingGraph.cpp
+++ b/js/src/vm/TraceLoggingGraph.cpp
@@ -278,25 +278,25 @@ TraceLoggerGraph::~TraceLoggerGraph()
 
         dictFile = nullptr;
     }
 
     if (!failed && treeFile) {
         // Make sure every start entry has a corresponding stop value.
         // We temporarily enable logging for this. Stop doesn't need any extra data,
         // so is safe to do even when we have encountered OOM.
-        enabled = 1;
+        enabled = true;
         while (stack.size() > 1)
             stopEvent(0);
-        enabled = 0;
+        enabled = false;
     }
 
     if (!failed && !flush()) {
         fprintf(stderr, "TraceLogging: Couldn't write the data to disk.\n");
-        enabled = 0;
+        enabled = false;
         failed = true;
     }
 
     if (treeFile) {
         fclose(treeFile);
         treeFile = nullptr;
     }
 
@@ -359,26 +359,26 @@ TraceLoggerGraph::startEvent(uint32_t id
 {
     if (failed || enabled == 0)
         return;
 
     if (!tree.hasSpaceForAdd()) {
         if (tree.size() >= treeSizeFlushLimit() || !tree.ensureSpaceBeforeAdd()) {
             if (!flush()) {
                 fprintf(stderr, "TraceLogging: Couldn't write the data to disk.\n");
-                enabled = 0;
+                enabled = false;
                 failed = true;
                 return;
             }
         }
     }
 
     if (!startEventInternal(id, timestamp)) {
         fprintf(stderr, "TraceLogging: Failed to start an event.\n");
-        enabled = 0;
+        enabled = false;
         failed = true;
         return;
     }
 }
 
 TraceLoggerGraph::StackEntry&
 TraceLoggerGraph::getActiveAncestor()
 {
@@ -457,17 +457,17 @@ TraceLoggerGraph::stopEvent(uint32_t id,
 }
 
 void
 TraceLoggerGraph::stopEvent(uint64_t timestamp)
 {
     if (enabled && stack.lastEntry().active()) {
         if (!updateStop(stack.lastEntry().treeId(), timestamp)) {
             fprintf(stderr, "TraceLogging: Failed to stop an event.\n");
-            enabled = 0;
+            enabled = false;
             failed = true;
             return;
         }
     }
     if (stack.size() == 1) {
         if (!enabled)
             return;