Index: lib/sanitizer_common/sanitizer_allocator.cc =================================================================== --- lib/sanitizer_common/sanitizer_allocator.cc +++ lib/sanitizer_common/sanitizer_allocator.cc @@ -69,7 +69,7 @@ } static void *RawInternalAlloc(uptr size, InternalAllocatorCache *cache) { - if (cache == 0) { + if (!cache) { SpinMutexLock l(&internal_allocator_cache_mu); return internal_allocator()->Allocate(&internal_allocator_cache, size, 8, false); Index: lib/sanitizer_common/sanitizer_procmaps_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_procmaps_linux.cc +++ lib/sanitizer_common/sanitizer_procmaps_linux.cc @@ -11,7 +11,9 @@ //===----------------------------------------------------------------------===// #include "sanitizer_platform.h" + #if SANITIZER_LINUX + #include "sanitizer_common.h" #include "sanitizer_procmaps.h" @@ -37,7 +39,7 @@ if (!offset) offset = &dummy; if (!protection) protection = &dummy; char *next_line = (char*)internal_memchr(current_, '\n', last - current_); - if (next_line == 0) + if (!next_line) next_line = last; // Example: 08048000-08056000 r-xp 00000000 03:0c 64593 /foo/bar *start = ParseHex(¤t_); @@ -85,6 +87,6 @@ return true; } -} // namespace __sanitizer +} // namespace __sanitizer -#endif // SANITIZER_LINUX +#endif // SANITIZER_LINUX Index: lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc +++ lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc @@ -282,7 +282,7 @@ internal_memset(&act, 0, sizeof(act)); act.sigaction = TracerThreadSignalHandler; act.sa_flags = SA_ONSTACK | SA_SIGINFO; - internal_sigaction_norestorer(kSyncSignals[i], &act, 0); + internal_sigaction_norestorer(kSyncSignals[i], &act, nullptr); } int exit_code = 0; @@ -406,7 +406,7 @@ CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_UNTRACED, &tracer_thread_argument, nullptr /* parent_tidptr */, nullptr /* newtls */, nullptr /* child_tidptr */); - internal_sigprocmask(SIG_SETMASK, &old_sigset, 0); + internal_sigprocmask(SIG_SETMASK, &old_sigset, nullptr); int local_errno = 0; if (internal_iserror(tracer_pid, &local_errno)) { VReport(1, "Failed spawning a tracer thread (errno %d).\n", local_errno); Index: lib/sanitizer_common/sanitizer_suppressions.cc =================================================================== --- lib/sanitizer_common/sanitizer_suppressions.cc +++ lib/sanitizer_common/sanitizer_suppressions.cc @@ -97,7 +97,7 @@ } if (!*prefix) return str; - return 0; + return nullptr; } void SuppressionContext::Parse(const char *str) { @@ -108,7 +108,7 @@ while (line[0] == ' ' || line[0] == '\t') line++; const char *end = internal_strchr(line, '\n'); - if (end == 0) + if (!end) end = line + internal_strlen(line); if (line != end && line[0] != '#') { const char *end2 = end; @@ -165,4 +165,4 @@ matched->push_back(&suppressions_[i]); } -} // namespace __sanitizer +} // namespace __sanitizer Index: lib/sanitizer_common/sanitizer_symbolizer.cc =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer.cc +++ lib/sanitizer_common/sanitizer_symbolizer.cc @@ -70,7 +70,7 @@ void Symbolizer::AddHooks(Symbolizer::StartSymbolizationHook start_hook, Symbolizer::EndSymbolizationHook end_hook) { - CHECK(start_hook_ == 0 && end_hook_ == 0); + CHECK((!start_hook_) && (!end_hook_)); start_hook_ = start_hook; end_hook_ = end_hook; } @@ -97,7 +97,7 @@ Symbolizer::Symbolizer(IntrusiveList tools) : module_names_(&mu_), n_modules_(0), modules_fresh_(false), tools_(tools), - start_hook_(0), end_hook_(0) {} + start_hook_(nullptr), end_hook_(nullptr) {} Symbolizer::SymbolizerScope::SymbolizerScope(const Symbolizer *sym) : sym_(sym) { @@ -110,4 +110,4 @@ sym_->end_hook_(); } -} // namespace __sanitizer +} // namespace __sanitizer Index: lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc +++ lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc @@ -64,7 +64,7 @@ data->buf[data->size + l] = '\0'; data->size += l; } -} // extern "C" +} // extern "C" char *CplusV3Demangle(const char *name) { CplusV3DemangleData data; @@ -83,7 +83,7 @@ InternalFree(data.buf); return 0; } -# endif // SANITIZER_CP_DEMANGLE +# endif // SANITIZER_CP_DEMANGLE struct SymbolizeCodeCallbackArg { SymbolizedStack *first; @@ -142,9 +142,9 @@ } static void ErrorCallback(void *, const char *, int) {} -} // extern "C" +} // extern "C" -} // namespace +} // anonymous namespace LibbacktraceSymbolizer *LibbacktraceSymbolizer::get(LowLevelAllocator *alloc) { // State created in backtrace_create_state is leaked. @@ -175,10 +175,10 @@ return true; } -#else // SANITIZER_LIBBACKTRACE +#else // SANITIZER_LIBBACKTRACE LibbacktraceSymbolizer *LibbacktraceSymbolizer::get(LowLevelAllocator *alloc) { - return 0; + return nullptr; } bool LibbacktraceSymbolizer::SymbolizePC(uptr addr, SymbolizedStack *stack) { @@ -190,7 +190,7 @@ return false; } -#endif // SANITIZER_LIBBACKTRACE +#endif // SANITIZER_LIBBACKTRACE static char *DemangleAlloc(const char *name, bool always_alloc) { #if SANITIZER_LIBBACKTRACE && SANITIZER_CP_DEMANGLE @@ -199,11 +199,11 @@ #endif if (always_alloc) return internal_strdup(name); - return 0; + return nullptr; } const char *LibbacktraceSymbolizer::Demangle(const char *name) { return DemangleAlloc(name, /*always_alloc*/ false); } -} // namespace __sanitizer +} // namespace __sanitizer Index: lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc +++ lib/sanitizer_common/sanitizer_symbolizer_libcdep.cc @@ -30,7 +30,7 @@ const char *ExtractInt(const char *str, const char *delims, int *result) { char *buff; const char *ret = ExtractToken(str, delims, &buff); - if (buff != 0) { + if (buff) { *result = (int)internal_atoll(buff); } InternalFree(buff); @@ -40,7 +40,7 @@ const char *ExtractUptr(const char *str, const char *delims, uptr *result) { char *buff; const char *ret = ExtractToken(str, delims, &buff); - if (buff != 0) { + if (buff) { *result = (uptr)internal_atoll(buff); } InternalFree(buff); @@ -140,7 +140,7 @@ const char **module_name, uptr *module_offset) { LoadedModule *module = FindModuleForAddress(address); - if (module == 0) + if (!module) return false; *module_name = module->full_name(); *module_offset = address - module->base_address(); @@ -172,7 +172,7 @@ modules_fresh_ = false; return FindModuleForAddress(address); } - return 0; + return nullptr; } Symbolizer *Symbolizer::GetOrInit() { @@ -239,7 +239,7 @@ // Windows, so extract tokens from the right hand side first. The column info is // also optional. static const char *ParseFileLineInfo(AddressInfo *info, const char *str) { - char *file_line_info = 0; + char *file_line_info = nullptr; str = ExtractToken(str, "\n", &file_line_info); CHECK(file_line_info); // Parse the last :, which must be there. @@ -274,7 +274,7 @@ bool top_frame = true; SymbolizedStack *last = res; while (true) { - char *function_name = 0; + char *function_name = nullptr; str = ExtractToken(str, "\n", &function_name); CHECK(function_name); if (function_name[0] == '\0') { @@ -301,11 +301,11 @@ // to address info to mark that names are unknown. if (0 == internal_strcmp(info->function, "??")) { InternalFree(info->function); - info->function = 0; + info->function = nullptr; } if (0 == internal_strcmp(info->file, "??")) { InternalFree(info->file); - info->file = 0; + info->file = nullptr; } } } @@ -370,16 +370,16 @@ Report("WARNING: Failed to use and restart external symbolizer!\n"); failed_to_start_ = true; } - return 0; + return nullptr; } const char *SymbolizerProcess::SendCommandImpl(const char *command) { if (input_fd_ == kInvalidFd || output_fd_ == kInvalidFd) - return 0; + return nullptr; if (!WriteToSymbolizer(command, internal_strlen(command))) - return 0; + return nullptr; if (!ReadFromSymbolizer(buffer_, kBufferSize)) - return 0; + return nullptr; return buffer_; } @@ -425,4 +425,4 @@ return true; } -} // namespace __sanitizer +} // namespace __sanitizer Index: lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc +++ lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc @@ -13,7 +13,9 @@ //===----------------------------------------------------------------------===// #include "sanitizer_platform.h" + #if SANITIZER_POSIX + #include "sanitizer_allocator_internal.h" #include "sanitizer_common.h" #include "sanitizer_flags.h" @@ -32,8 +34,8 @@ #include #if SANITIZER_MAC -#include // for forkpty() -#endif // SANITIZER_MAC +#include // for forkpty() +#endif // SANITIZER_MAC // C++ demangling function, as required by Itanium C++ ABI. This is weak, // because we do not require a C++ ABI library to be linked to a program @@ -55,7 +57,7 @@ // the returned value. if (__cxxabiv1::__cxa_demangle) if (const char *demangled_name = - __cxxabiv1::__cxa_demangle(name, 0, 0, 0)) + __cxxabiv1::__cxa_demangle(name, nullptr, nullptr, nullptr)) return demangled_name; return name; @@ -98,12 +100,12 @@ termflags.c_oflag &= ~ONLCR; termflags.c_lflag &= ~ECHO; tcsetattr(fd, TCSANOW, &termflags); -#else // SANITIZER_MAC +#else // SANITIZER_MAC UNIMPLEMENTED(); -#endif // SANITIZER_MAC +#endif // SANITIZER_MAC } else { - int *infd = NULL; - int *outfd = NULL; + int *infd = nullptr; + int *outfd = nullptr; // The client program may close its stdin and/or stdout and/or stderr // thus allowing socketpair to reuse file descriptors 0, 1 or 2. // In this case the communication between the forked processes may be @@ -121,7 +123,7 @@ "external symbolizer (errno: %d)\n", errno); return false; } else if (sock_pair[i][0] > 2 && sock_pair[i][1] > 2) { - if (infd == NULL) { + if (!infd) { infd = sock_pair[i]; } else { outfd = sock_pair[i]; @@ -264,7 +266,7 @@ private: const char *SendCommand(const char *module_name, uptr module_offset) { - Addr2LineProcess *addr2line = 0; + Addr2LineProcess *addr2line = nullptr; for (uptr i = 0; i < addr2line_pool_.size(); ++i) { if (0 == internal_strcmp(module_name, addr2line_pool_[i]->module_name())) { @@ -305,16 +307,16 @@ SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE int __sanitizer_symbolize_demangle(const char *Name, char *Buffer, int MaxLength); -} // extern "C" +} // extern "C" class InternalSymbolizer : public SymbolizerTool { public: static InternalSymbolizer *get(LowLevelAllocator *alloc) { - if (__sanitizer_symbolize_code != 0 && - __sanitizer_symbolize_data != 0) { + if (__sanitizer_symbolize_code && + __sanitizer_symbolize_data) { return new(*alloc) InternalSymbolizer(); } - return 0; + return nullptr; } bool SymbolizePC(uptr addr, SymbolizedStack *stack) override { @@ -364,14 +366,14 @@ static const int kMaxDemangledNameSize = 1024; char buffer_[kBufferSize]; }; -#else // SANITIZER_SUPPORTS_WEAK_HOOKS +#else // SANITIZER_SUPPORTS_WEAK_HOOKS class InternalSymbolizer : public SymbolizerTool { public: static InternalSymbolizer *get(LowLevelAllocator *alloc) { return 0; } }; -#endif // SANITIZER_SUPPORTS_WEAK_HOOKS +#endif // SANITIZER_SUPPORTS_WEAK_HOOKS const char *Symbolizer::PlatformDemangle(const char *name) { return DemangleCXXABI(name); @@ -417,7 +419,7 @@ VReport(2, "Using atos found at: %s\n", found_path); return new(*allocator) AtosSymbolizer(found_path, allocator); } -#endif // SANITIZER_MAC +#endif // SANITIZER_MAC if (common_flags()->allow_addr2line) { if (const char *found_path = FindPathToBinary("addr2line")) { VReport(2, "Using addr2line found at: %s\n", found_path); @@ -453,7 +455,7 @@ #if SANITIZER_MAC VReport(2, "Using dladdr symbolizer.\n"); list->push_back(new(*allocator) DlAddrSymbolizer()); -#endif // SANITIZER_MAC +#endif // SANITIZER_MAC } Symbolizer *Symbolizer::PlatformInit() { @@ -463,6 +465,6 @@ return new(symbolizer_allocator_) Symbolizer(list); } -} // namespace __sanitizer +} // namespace __sanitizer -#endif // SANITIZER_POSIX +#endif // SANITIZER_POSIX Index: lib/sanitizer_common/sanitizer_thread_registry.cc =================================================================== --- lib/sanitizer_common/sanitizer_thread_registry.cc +++ lib/sanitizer_common/sanitizer_thread_registry.cc @@ -19,7 +19,7 @@ ThreadContextBase::ThreadContextBase(u32 tid) : tid(tid), unique_id(0), reuse_count(), os_id(0), user_id(0), status(ThreadStatusInvalid), - detached(false), parent_tid(0), next(0) { + detached(false), parent_tid(0), next(nullptr) { name[0] = '\0'; } @@ -79,7 +79,7 @@ void ThreadContextBase::Reset() { status = ThreadStatusInvalid; - SetName(0); + SetName(nullptr); OnReset(); } @@ -159,7 +159,7 @@ CheckLocked(); for (u32 tid = 0; tid < n_contexts_; tid++) { ThreadContextBase *tctx = threads_[tid]; - if (tctx == 0) + if (!tctx) continue; cb(tctx, arg); } @@ -169,7 +169,7 @@ BlockingMutexLock l(&mtx_); for (u32 tid = 0; tid < n_contexts_; tid++) { ThreadContextBase *tctx = threads_[tid]; - if (tctx != 0 && cb(tctx, arg)) + if (tctx && cb(tctx, arg)) return tctx->tid; } return kUnknownTid; @@ -180,10 +180,10 @@ CheckLocked(); for (u32 tid = 0; tid < n_contexts_; tid++) { ThreadContextBase *tctx = threads_[tid]; - if (tctx != 0 && cb(tctx, arg)) + if (tctx && cb(tctx, arg)) return tctx; } - return 0; + return nullptr; } static bool FindThreadContextByOsIdCallback(ThreadContextBase *tctx, @@ -210,7 +210,7 @@ BlockingMutexLock l(&mtx_); for (u32 tid = 0; tid < n_contexts_; tid++) { ThreadContextBase *tctx = threads_[tid]; - if (tctx != 0 && tctx->user_id == user_id && + if (tctx && tctx->user_id == user_id && tctx->status != ThreadStatusInvalid) { tctx->SetName(name); return; @@ -292,10 +292,10 @@ ThreadContextBase *ThreadRegistry::QuarantinePop() { if (invalid_threads_.size() == 0) - return 0; + return nullptr; ThreadContextBase *tctx = invalid_threads_.front(); invalid_threads_.pop_front(); return tctx; } -} // namespace __sanitizer +} // namespace __sanitizer Index: lib/sanitizer_common/sanitizer_tls_get_addr.cc =================================================================== --- lib/sanitizer_common/sanitizer_tls_get_addr.cc +++ lib/sanitizer_common/sanitizer_tls_get_addr.cc @@ -17,6 +17,7 @@ #include "sanitizer_platform_interceptors.h" namespace __sanitizer { + #if SANITIZER_INTERCEPT_TLS_GET_ADDR // The actual parameter that comes to __tls_get_addr @@ -80,12 +81,12 @@ DTLS::DTV *DTLS_on_tls_get_addr(void *arg_void, void *res, uptr static_tls_begin, uptr static_tls_end) { - if (!common_flags()->intercept_tls_get_addr) return 0; + if (!common_flags()->intercept_tls_get_addr) return nullptr; TlsGetAddrParam *arg = reinterpret_cast(arg_void); uptr dso_id = arg->dso_id; - if (dtls.dtv_size == kDestroyedThread) return 0; + if (dtls.dtv_size == kDestroyedThread) return nullptr; DTLS_Resize(dso_id + 1); - if (dtls.dtv[dso_id].beg) return 0; + if (dtls.dtv[dso_id].beg) return nullptr; uptr tls_size = 0; uptr tls_beg = reinterpret_cast(res) - arg->offset; VPrintf(2, "__tls_get_addr: %p {%p,%p} => %p; tls_beg: %p; sp: %p " @@ -127,11 +128,11 @@ DTLS *DTLS_Get() { return &dtls; } -#else +#else // SANITIZER_INTERCEPT_TLS_GET_ADDR void DTLS_on_libc_memalign(void *ptr, uptr size) {} DTLS::DTV *DTLS_on_tls_get_addr(void *arg, void *res) { return 0; } DTLS *DTLS_Get() { return 0; } void DTLS_Destroy() {} -#endif // SANITIZER_INTERCEPT_TLS_GET_ADDR +#endif // SANITIZER_INTERCEPT_TLS_GET_ADDR -} // namespace __sanitizer +} // namespace __sanitizer Index: lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc =================================================================== --- lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc +++ lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc @@ -12,7 +12,9 @@ //===----------------------------------------------------------------------===// #include "sanitizer_platform.h" + #if SANITIZER_FREEBSD || SANITIZER_LINUX + #include "sanitizer_common.h" #include "sanitizer_stacktrace.h" @@ -71,7 +73,7 @@ release_my_map_info_list = 0; } } -#endif +#endif // SANITIZER_ANDROID #ifdef __arm__ #define UNWIND_STOP _URC_END_OF_STACK @@ -139,7 +141,7 @@ CHECK(map); InternalScopedBuffer frames(kStackTraceMax); // siginfo argument appears to be unused. - sptr res = unwind_backtrace_signal_arch(/* siginfo */ 0, context, map, + sptr res = unwind_backtrace_signal_arch(/* siginfo */ nullptr, context, map, frames.data(), /* ignore_depth */ 0, max_depth); release_my_map_info_list(map); @@ -153,6 +155,6 @@ trace_buffer[size++] = frames[i].absolute_pc + 2; } -} // namespace __sanitizer +} // namespace __sanitizer -#endif // SANITIZER_FREEBSD || SANITIZER_LINUX +#endif // SANITIZER_FREEBSD || SANITIZER_LINUX Index: lib/ubsan/ubsan_diag.cc =================================================================== --- lib/ubsan/ubsan_diag.cc +++ lib/ubsan/ubsan_diag.cc @@ -12,7 +12,9 @@ //===----------------------------------------------------------------------===// #include "ubsan_platform.h" + #if CAN_SANITIZE_UB + #include "ubsan_diag.h" #include "ubsan_init.h" #include "ubsan_flags.h" @@ -39,7 +41,7 @@ if (StackTrace::WillUseFastUnwind(false)) return; BufferedStackTrace stack; - stack.Unwind(kStackTraceMax, pc, bp, 0, 0, 0, false); + stack.Unwind(kStackTraceMax, pc, bp, nullptr, 0, 0, false); stack.Print(); } @@ -89,7 +91,7 @@ const char *Note() const { return Black(); } const char *EndNote() const { return Default(); } }; -} +} // anonymous namespace SymbolizedStack *__ubsan::getSymbolizedLocation(uptr PC) { InitAsStandaloneIfNecessary(); @@ -222,7 +224,7 @@ /// Find the earliest-starting range in Ranges which ends after Loc. static Range *upperBound(MemoryLocation Loc, Range *Ranges, unsigned NumRanges) { - Range *Best = 0; + Range *Best = nullptr; for (unsigned I = 0; I != NumRanges; ++I) if (Ranges[I].getEnd().getMemoryLocation() > Loc && (!Best || @@ -292,7 +294,7 @@ Printf("%s\n", Decor.EndHighlight()); // Go over the line again, and print names for the ranges. - InRange = 0; + InRange = nullptr; unsigned Spaces = 0; for (uptr P = Min; P != Max; ++P) { if (!InRange || InRange->getEnd().getMemoryLocation() == P) @@ -388,4 +390,4 @@ return suppression_ctx->Match(TypeName, kVptrCheck, &s); } -#endif // CAN_SANITIZE_UB +#endif // CAN_SANITIZE_UB Index: lib/ubsan/ubsan_type_hash_itanium.cc =================================================================== --- lib/ubsan/ubsan_type_hash_itanium.cc +++ lib/ubsan/ubsan_type_hash_itanium.cc @@ -13,7 +13,9 @@ #include "sanitizer_common/sanitizer_platform.h" #include "ubsan_platform.h" + #if CAN_SANITIZE_UB && !SANITIZER_WINDOWS + #include "ubsan_type_hash.h" #include "sanitizer_common/sanitizer_common.h" @@ -29,7 +31,7 @@ const char *__type_name; }; -} +} // namespace std namespace __cxxabiv1 { @@ -69,7 +71,7 @@ __base_class_type_info base_info[1]; }; -} +} // namespace __cxxabiv1 namespace abi = __cxxabiv1; @@ -163,7 +165,7 @@ dynamic_cast(Derived); if (!VTI) // No base class subobjects. - return 0; + return nullptr; for (unsigned int base = 0; base != VTI->base_count; ++base) { sptr OffsetHere = VTI->base_info[base].__offset_flags >> @@ -178,7 +180,7 @@ return Base; } - return 0; + return nullptr; } namespace { @@ -191,18 +193,19 @@ /// The type_info object describing the most-derived class type. std::type_info *TypeInfo; }; + VtablePrefix *getVtablePrefix(void *Vtable) { VtablePrefix *Vptr = reinterpret_cast(Vtable); if (!Vptr) - return 0; + return nullptr; VtablePrefix *Prefix = Vptr - 1; if (!Prefix->TypeInfo) // This can't possibly be a valid vtable. - return 0; + return nullptr; return Prefix; } -} +} // anonymous namespace bool __ubsan::checkDynamicType(void *Object, void *Type, HashValue Hash) { // A crash anywhere within this function probably means the vptr is corrupted. @@ -240,7 +243,7 @@ __ubsan::getDynamicTypeInfoFromVtable(void *VtablePtr) { VtablePrefix *Vtable = getVtablePrefix(VtablePtr); if (!Vtable) - return DynamicTypeInfo(0, 0, 0); + return DynamicTypeInfo(nullptr, 0, nullptr); const abi::__class_type_info *ObjectType = findBaseAtOffset( static_cast(Vtable->TypeInfo), -Vtable->Offset); @@ -248,4 +251,4 @@ ObjectType ? ObjectType->__type_name : ""); } -#endif // CAN_SANITIZE_UB && !SANITIZER_WINDOWS +#endif // CAN_SANITIZE_UB && !SANITIZER_WINDOWS