From d7ea6b714258b732407cef68072f55ee4d24f00c Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Wed, 18 Oct 2017 09:49:45 -0700 Subject: [PATCH] Use nullptr rather than 0 when initializing pointers 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 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 | 2 +- folly/PackedSyncPtr.h | 2 +- folly/String.cpp | 16 ++++++++-------- folly/fibers/BoostContextCompatibility.h | 7 ++++--- folly/hash/test/SpookyHashV1Test.cpp | 2 +- folly/hash/test/SpookyHashV2Test.cpp | 2 +- folly/test/AtomicHashMapTest.cpp | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/folly/Hash.h b/folly/Hash.h index 1151dc43..410d2720 100644 --- a/folly/Hash.h +++ b/folly/Hash.h @@ -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; } diff --git a/folly/PackedSyncPtr.h b/folly/PackedSyncPtr.h index a5dd5184..10902400 100644 --- a/folly/PackedSyncPtr.h +++ b/folly/PackedSyncPtr.h @@ -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(initialPtr); CHECK(!(intPtr >> 48)); data_.init(intPtr); diff --git a/folly/String.cpp b/folly/String.cpp index 0fb3f325..097e5bbf 100644 --- a/folly/String.cpp +++ b/folly/String.cpp @@ -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] = { diff --git a/folly/fibers/BoostContextCompatibility.h b/folly/fibers/BoostContextCompatibility.h index 280162b1..2f6cc127 100644 --- a/folly/fibers/BoostContextCompatibility.h +++ b/folly/fibers/BoostContextCompatibility.h @@ -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(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(context)); } diff --git a/folly/hash/test/SpookyHashV1Test.cpp b/folly/hash/test/SpookyHashV1Test.cpp index 054c37ca..d5987f8e 100644 --- a/folly/hash/test/SpookyHashV1Test.cpp +++ b/folly/hash/test/SpookyHashV1Test.cpp @@ -315,7 +315,7 @@ void DoTimingBig(int seed) for (int i=0; i