Use nullptr rather than 0 when initializing pointers
authorChristopher Dykes <cdykes@fb.com>
Wed, 18 Oct 2017 16:49:45 +0000 (09:49 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 18 Oct 2017 16:51:38 +0000 (09:51 -0700)
Summary:
Because we do this in a few places, and `nullptr` makes it far clearer what the intention is.
Note that with `-Wzero-as-null-pointer-constant` under GCC, doing `std::function<void()> f = {}` initializes `f` with a `0` rather than `nullptr`, triggering the warning, so I've enabled it there as well.
It is not currently possible to actually enable `-Wzero-as-null-pointer-constant`, because GCC 5 reports conversions resulting from a default value as occuring at the call-site rather than at the location where the parameter is defined, and the default allocator in libstdc++ is not clean for this particular warning -_-...

Reviewed By: yfeldblum

Differential Revision: D6046746

fbshipit-source-id: 6135bb20a503c861838575cf973324d74d75ca69

folly/Hash.h
folly/PackedSyncPtr.h
folly/String.cpp
folly/fibers/BoostContextCompatibility.h
folly/hash/test/SpookyHashV1Test.cpp
folly/hash/test/SpookyHashV2Test.cpp
folly/test/AtomicHashMapTest.cpp

index 1151dc4350725acbafdaf880c6d425ee52b2804f..410d2720db540cf6c586ed91f7597a92c9463daa 100644 (file)
@@ -310,7 +310,7 @@ inline uint32_t hsieh_hash32_buf(const void* buf, size_t len) {
   uint32_t tmp;
   size_t rem;
 
-  if (len <= 0 || buf == 0) {
+  if (len <= 0 || buf == nullptr) {
     return 0;
   }
 
index a5dd51847ad99625e209d027e61b840458d95f7f..1090240085d965de88a928e85d9ef9b4285a7b3c 100644 (file)
@@ -74,7 +74,7 @@ class PackedSyncPtr {
    * (We are avoiding a constructor to ensure gcc allows us to put
    * this class in packed structures.)
    */
-  void init(T* initialPtr = 0, uint16_t initialExtra = 0) {
+  void init(T* initialPtr = nullptr, uint16_t initialExtra = 0) {
     auto intPtr = reinterpret_cast<uintptr_t>(initialPtr);
     CHECK(!(intPtr >> 48));
     data_.init(intPtr);
index 0fb3f32593f8583341521650614d4601d28cac4e..097e5bbfd4c7b2cd86ed2b388ee557bea5124952 100644 (file)
@@ -181,7 +181,7 @@ const PrettySuffix kPrettyTimeSuffixes[] = {
   { "ns", 1e-9L },
   { "ps", 1e-12L },
   { "s ", 0 },
-  { 0, 0 },
+  { nullptr, 0 },
 };
 
 const PrettySuffix kPrettyBytesMetricSuffixes[] = {
@@ -190,7 +190,7 @@ const PrettySuffix kPrettyBytesMetricSuffixes[] = {
   { "MB", 1e6L },
   { "kB", 1e3L },
   { "B ", 0L },
-  { 0, 0 },
+  { nullptr, 0 },
 };
 
 const PrettySuffix kPrettyBytesBinarySuffixes[] = {
@@ -199,7 +199,7 @@ const PrettySuffix kPrettyBytesBinarySuffixes[] = {
   { "MB", int64_t(1) << 20 },
   { "kB", int64_t(1) << 10 },
   { "B ", 0L },
-  { 0, 0 },
+  { nullptr, 0 },
 };
 
 const PrettySuffix kPrettyBytesBinaryIECSuffixes[] = {
@@ -208,7 +208,7 @@ const PrettySuffix kPrettyBytesBinaryIECSuffixes[] = {
   { "MiB", int64_t(1) << 20 },
   { "KiB", int64_t(1) << 10 },
   { "B  ", 0L },
-  { 0, 0 },
+  { nullptr, 0 },
 };
 
 const PrettySuffix kPrettyUnitsMetricSuffixes[] = {
@@ -217,7 +217,7 @@ const PrettySuffix kPrettyUnitsMetricSuffixes[] = {
   { "M",    1e6L },
   { "k",    1e3L },
   { " ",      0  },
-  { 0, 0 },
+  { nullptr, 0 },
 };
 
 const PrettySuffix kPrettyUnitsBinarySuffixes[] = {
@@ -226,7 +226,7 @@ const PrettySuffix kPrettyUnitsBinarySuffixes[] = {
   { "M", int64_t(1) << 20 },
   { "k", int64_t(1) << 10 },
   { " ", 0 },
-  { 0, 0 },
+  { nullptr, 0 },
 };
 
 const PrettySuffix kPrettyUnitsBinaryIECSuffixes[] = {
@@ -235,7 +235,7 @@ const PrettySuffix kPrettyUnitsBinaryIECSuffixes[] = {
   { "Mi", int64_t(1) << 20 },
   { "Ki", int64_t(1) << 10 },
   { "  ", 0 },
-  { 0, 0 },
+  { nullptr, 0 },
 };
 
 const PrettySuffix kPrettySISuffixes[] = {
@@ -260,7 +260,7 @@ const PrettySuffix kPrettySISuffixes[] = {
   { "z", 1e-21L },
   { "y", 1e-24L },
   { " ", 0 },
-  { 0, 0}
+  { nullptr, 0}
 };
 
 const PrettySuffix* const kPrettySuffixes[PRETTY_NUM_TYPES] = {
index 280162b1c79b5b9d2166d3aea4ea617aeb17c714..2f6cc127e32c29708051fe32cd91827708ab9df9 100644 (file)
@@ -97,7 +97,8 @@ class FiberImpl {
 
   void deactivate() {
 #if BOOST_VERSION >= 106100
-    auto transfer = boost::context::detail::jump_fcontext(mainContext_, 0);
+    auto transfer =
+        boost::context::detail::jump_fcontext(mainContext_, nullptr);
     mainContext_ = transfer.fctx;
     auto context = reinterpret_cast<intptr_t>(transfer.data);
 #elif BOOST_VERSION >= 105600
@@ -105,9 +106,9 @@ class FiberImpl {
         boost::context::jump_fcontext(&fiberContext_, mainContext_, 0);
 #elif BOOST_VERSION >= 105200
     auto context =
-        boost::context::jump_fcontext(fiberContext_, &mainContext_, 0);
+        boost::context::jump_fcontext(fiberContext_, &mainContext_, nullptr);
 #else
-    auto context = jump_fcontext(&fiberContext_, &mainContext_, 0);
+    auto context = jump_fcontext(&fiberContext_, &mainContext_, nullptr);
 #endif
     DCHECK_EQ(this, reinterpret_cast<FiberImpl*>(context));
   }
index 054c37cac06816e22bc4d32f8b331f4ebd34cda6..d5987f8e44de846b6f62d6bc3bbed1d00f9945c4 100644 (file)
@@ -315,7 +315,7 @@ void DoTimingBig(int seed)
     for (int i=0; i<NUMBUF; ++i)
     {
         free(buf[i]);
-        buf[i] = 0;
+        buf[i] = nullptr;
     }
 }
 #undef NUMBUF
index 406c1007b606a7183060dd5cd26ecf3cb1e8c7fe..4d01a2c3444337b2a2bcd45b788810175000538c 100644 (file)
@@ -305,7 +305,7 @@ void DoTimingBig(int seed)
     for (int i=0; i<NUMBUF; ++i)
     {
         free(buf[i]);
-        buf[i] = 0;
+        buf[i] = nullptr;
     }
 }
 #undef NUMBUF
index 147d2238ef1a209b530fcc68bbf8a50b593ec0a3..f204f8ff8cb0bbe1ed38aed5dec524f8af719fb6 100644 (file)
@@ -44,7 +44,7 @@ const int maxBMElements = int(FLAGS_numBMElements * LF); // hit our target LF.
 
 static int64_t nowInUsec() {
   timeval tv;
-  gettimeofday(&tv, 0);
+  gettimeofday(&tv, nullptr);
   return int64_t(tv.tv_sec) * 1000 * 1000 + tv.tv_usec;
 }