Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: Id869744db54b5b366454a5e13b467ac1f4df2845
diff --git a/cmdline/cmdline_parser_test.cc b/cmdline/cmdline_parser_test.cc
index a52e163..a33d537 100644
--- a/cmdline/cmdline_parser_test.cc
+++ b/cmdline/cmdline_parser_test.cc
@@ -59,7 +59,7 @@
template <typename T>
bool UsuallyEquals(const T& expected, const T& actual,
typename std::enable_if<
- detail::SupportsEqualityOperator<T>::value>::type* = 0) {
+ detail::SupportsEqualityOperator<T>::value>::type* = nullptr) {
return expected == actual;
}
@@ -73,8 +73,8 @@
template <typename T, typename ... Ignore>
bool UsuallyEquals(const T& expected, const T& actual,
const Ignore& ... more ATTRIBUTE_UNUSED,
- typename std::enable_if<std::is_pod<T>::value>::type* = 0,
- typename std::enable_if<!detail::SupportsEqualityOperator<T>::value>::type* = 0
+ typename std::enable_if<std::is_pod<T>::value>::type* = nullptr,
+ typename std::enable_if<!detail::SupportsEqualityOperator<T>::value>::type* = nullptr
) {
return memcmp(std::addressof(expected), std::addressof(actual), sizeof(T)) == 0;
}
diff --git a/cmdline/detail/cmdline_parse_argument_detail.h b/cmdline/detail/cmdline_parse_argument_detail.h
index 65c1114..d011e7f 100644
--- a/cmdline/detail/cmdline_parse_argument_detail.h
+++ b/cmdline/detail/cmdline_parse_argument_detail.h
@@ -90,7 +90,7 @@
struct CmdlineParserArgumentInfo {
// This version will only be used if TArg is arithmetic and thus has the <= operators.
template <typename T = TArg> // Necessary to get SFINAE to kick in.
- bool CheckRange(const TArg& value, typename EnableIfNumeric<T>::type* = 0) {
+ bool CheckRange(const TArg& value, typename EnableIfNumeric<T>::type* = nullptr) {
if (has_range_) {
return min_ <= value && value <= max_;
}
@@ -99,7 +99,7 @@
// This version will be used at other times when TArg is not arithmetic.
template <typename T = TArg>
- bool CheckRange(const TArg&, typename DisableIfNumeric<T>::type* = 0) {
+ bool CheckRange(const TArg&, typename DisableIfNumeric<T>::type* = nullptr) {
assert(!has_range_);
return true;
}
diff --git a/cmdline/detail/cmdline_parser_detail.h b/cmdline/detail/cmdline_parser_detail.h
index 4c26ba3..2078d7a 100644
--- a/cmdline/detail/cmdline_parser_detail.h
+++ b/cmdline/detail/cmdline_parser_detail.h
@@ -90,7 +90,7 @@
template <typename T>
std::string ToStringAny(const T& value,
typename std::enable_if<
- SupportsInsertionOperator<T>::value>::type* = 0) {
+ SupportsInsertionOperator<T>::value>::type* = nullptr) {
std::stringstream stream;
stream << value;
return stream.str();
@@ -99,7 +99,7 @@
template <typename T>
std::string ToStringAny(const std::vector<T> value,
typename std::enable_if<
- SupportsInsertionOperator<T>::value>::type* = 0) {
+ SupportsInsertionOperator<T>::value>::type* = nullptr) {
std::stringstream stream;
stream << "vector{";
@@ -118,7 +118,7 @@
template <typename T>
std::string ToStringAny(const T&,
typename std::enable_if<
- !SupportsInsertionOperator<T>::value>::type* = 0
+ !SupportsInsertionOperator<T>::value>::type* = nullptr
) {
return std::string("(unknown type [no operator<< implemented] for )");
}
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index a1a547c..9351fb5 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -1904,7 +1904,7 @@
DCHECK(target != nullptr);
const void* oat_code_offset =
target->GetEntryPointFromQuickCompiledCodePtrSize(pointer_size_);
- if (oat_code_offset != 0) {
+ if (oat_code_offset != nullptr) {
DCHECK(!writer_->GetCompilerOptions().IsBootImage());
DCHECK(!Runtime::Current()->GetClassLinker()->IsQuickResolutionStub(oat_code_offset));
DCHECK(!Runtime::Current()->GetClassLinker()->IsQuickToInterpreterBridge(oat_code_offset));
diff --git a/libartbase/base/bit_struct_detail.h b/libartbase/base/bit_struct_detail.h
index 68c2e44..60de1b6 100644
--- a/libartbase/base/bit_struct_detail.h
+++ b/libartbase/base/bit_struct_detail.h
@@ -85,7 +85,7 @@
static constexpr FalseT Test(...);
public:
- static constexpr bool value = decltype(Test<T>(0))::value;
+ static constexpr bool value = decltype(Test<T>(nullptr))::value;
};
// Infer the type of the member of &T::M.
diff --git a/libartbase/base/mem_map_fuchsia.cc b/libartbase/base/mem_map_fuchsia.cc
index db31efb..d1c92ce 100644
--- a/libartbase/base/mem_map_fuchsia.cc
+++ b/libartbase/base/mem_map_fuchsia.cc
@@ -41,8 +41,8 @@
ZX_INFO_VMAR,
&vmarinfo,
sizeof(vmarinfo),
- NULL,
- NULL), ZX_OK) << "could not find info from root vmar";
+ nullptr,
+ nullptr), ZX_OK) << "could not find info from root vmar";
uintptr_t lower_mem_start = FUCHSIA_LOWER_MEM_START - vmarinfo.base;
fuchsia_lowmem_size = FUCHSIA_LOWER_MEM_SIZE;
@@ -97,8 +97,8 @@
ZX_INFO_VMAR,
&vmarinfo,
sizeof(vmarinfo),
- NULL,
- NULL);
+ nullptr,
+ nullptr);
if (status < 0 || reinterpret_cast<uintptr_t>(start) < vmarinfo.base) {
errno = EINVAL;
return MAP_FAILED;
diff --git a/libdexfile/dex/code_item_accessors.h b/libdexfile/dex/code_item_accessors.h
index 5786d3f..695cc7b 100644
--- a/libdexfile/dex/code_item_accessors.h
+++ b/libdexfile/dex/code_item_accessors.h
@@ -80,7 +80,7 @@
uint32_t insns_size_in_code_units_ = 0;
// Pointer to the instructions, null if there is no code item.
- const uint16_t* insns_ = 0;
+ const uint16_t* insns_ = nullptr;
};
// Abstracts accesses to code item fields other than debug info for CompactDexFile and
diff --git a/openjdkjvm/OpenjdkJvm.cc b/openjdkjvm/OpenjdkJvm.cc
index df002b6..8d0200c 100644
--- a/openjdkjvm/OpenjdkJvm.cc
+++ b/openjdkjvm/OpenjdkJvm.cc
@@ -187,7 +187,7 @@
}
JNIEXPORT int jio_vfprintf(FILE* fp, const char* fmt, va_list args) {
- assert(fp != NULL);
+ assert(fp != nullptr);
return vfprintf(fp, fmt, args);
}
@@ -203,7 +203,7 @@
JNIEXPORT jlong JVM_CurrentTimeMillis(JNIEnv* env ATTRIBUTE_UNUSED,
jclass clazz ATTRIBUTE_UNUSED) {
struct timeval tv;
- gettimeofday(&tv, (struct timezone *) NULL);
+ gettimeofday(&tv, (struct timezone *) nullptr);
jlong when = tv.tv_sec * 1000LL + tv.tv_usec / 1000;
return when;
}
@@ -319,8 +319,8 @@
jstring javaFilename,
jobject javaLoader) {
ScopedUtfChars filename(env, javaFilename);
- if (filename.c_str() == NULL) {
- return NULL;
+ if (filename.c_str() == nullptr) {
+ return nullptr;
}
std::string error_msg;
@@ -348,7 +348,7 @@
art::ScopedObjectAccess soa(env);
art::MutexLock mu(soa.Self(), *art::Locks::thread_list_lock_);
art::Thread* thread = art::Thread::FromManagedThread(soa, jthread);
- if (thread != NULL) {
+ if (thread != nullptr) {
thread->SetNativePriority(prio);
}
}
@@ -421,7 +421,7 @@
art::SuspendReason::kInternal,
&timed_out);
}
- if (thread != NULL) {
+ if (thread != nullptr) {
{
art::ScopedObjectAccess soa(env);
thread->SetThreadName(name.c_str());
diff --git a/openjdkjvmti/ti_timers.cc b/openjdkjvmti/ti_timers.cc
index 24fb041..11b58c4 100644
--- a/openjdkjvmti/ti_timers.cc
+++ b/openjdkjvmti/ti_timers.cc
@@ -83,7 +83,7 @@
// No CLOCK_MONOTONIC support on older Mac OS.
struct timeval t;
t.tv_sec = t.tv_usec = 0;
- gettimeofday(&t, NULL);
+ gettimeofday(&t, nullptr);
*nanos_ptr = static_cast<jlong>(t.tv_sec)*1000000000LL + static_cast<jlong>(t.tv_usec)*1000LL;
#endif
diff --git a/runtime/hprof/hprof.cc b/runtime/hprof/hprof.cc
index dc42cfa..3f44928 100644
--- a/runtime/hprof/hprof.cc
+++ b/runtime/hprof/hprof.cc
@@ -1590,7 +1590,7 @@
if (obj == nullptr) {
return;
}
- MarkRootObject(obj, 0, xlate[info.GetType()], info.GetThreadId());
+ MarkRootObject(obj, nullptr, xlate[info.GetType()], info.GetThreadId());
}
// If "direct_to_ddms" is true, the other arguments are ignored, and data is
diff --git a/runtime/interpreter/unstarted_runtime.cc b/runtime/interpreter/unstarted_runtime.cc
index 22a6e9d..9049b2b 100644
--- a/runtime/interpreter/unstarted_runtime.cc
+++ b/runtime/interpreter/unstarted_runtime.cc
@@ -1965,7 +1965,7 @@
const auto& iter = invoke_handlers_.find(name);
if (iter != invoke_handlers_.end()) {
// Clear out the result in case it's not zeroed out.
- result->SetL(0);
+ result->SetL(nullptr);
// Push the shadow frame. This is so the failing method can be seen in abort dumps.
self->PushShadowFrame(shadow_frame);
@@ -1986,7 +1986,7 @@
const auto& iter = jni_handlers_.find(name);
if (iter != jni_handlers_.end()) {
// Clear out the result in case it's not zeroed out.
- result->SetL(0);
+ result->SetL(nullptr);
(*iter->second)(self, method, receiver, args, result);
} else if (Runtime::Current()->IsActiveTransaction()) {
AbortTransactionF(self, "Attempt to invoke native method in non-started runtime: %s",
diff --git a/runtime/jdwp/jdwp_event.cc b/runtime/jdwp/jdwp_event.cc
index 9409b76..0353ea7 100644
--- a/runtime/jdwp/jdwp_event.cc
+++ b/runtime/jdwp/jdwp_event.cc
@@ -1159,7 +1159,7 @@
}
basket.className = Dbg::GetClassName(basket.locationClass.Get());
basket.exceptionClass.Assign(exception_object->GetClass());
- basket.caught = (pCatchLoc->method != 0);
+ basket.caught = (pCatchLoc->method != nullptr);
basket.thisPtr.Assign(thisPtr);
/* don't try to post an exception caused by the debugger */
diff --git a/runtime/jni/check_jni.cc b/runtime/jni/check_jni.cc
index 66bd74b..c5e8830 100644
--- a/runtime/jni/check_jni.cc
+++ b/runtime/jni/check_jni.cc
@@ -1462,7 +1462,7 @@
break;
}
}
- return 0;
+ return nullptr;
}
void AbortF(const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))) {
diff --git a/runtime/method_handles.cc b/runtime/method_handles.cc
index 01a32a2..570fc48 100644
--- a/runtime/method_handles.cc
+++ b/runtime/method_handles.cc
@@ -484,7 +484,7 @@
first_dest_reg,
new_shadow_frame)) {
DCHECK(self->IsExceptionPending());
- result->SetL(0);
+ result->SetL(nullptr);
return false;
}
} else {
@@ -500,7 +500,7 @@
operands,
new_shadow_frame)) {
DCHECK(self->IsExceptionPending());
- result->SetL(0);
+ result->SetL(nullptr);
return false;
}
}
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index cdba6b2..b598df3 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -233,13 +233,13 @@
if (base_address == nullptr) {
ScopedObjectAccess soa(env);
ThrowWrappedIOException("dexFileBuffer not direct");
- return 0;
+ return nullptr;
}
std::unique_ptr<MemMap> dex_mem_map(AllocateDexMemoryMap(env, start, end));
if (dex_mem_map == nullptr) {
DCHECK(Thread::Current()->IsExceptionPending());
- return 0;
+ return nullptr;
}
size_t length = static_cast<size_t>(end - start);
@@ -255,7 +255,7 @@
std::unique_ptr<MemMap> dex_mem_map(AllocateDexMemoryMap(env, start, end));
if (dex_mem_map == nullptr) {
DCHECK(Thread::Current()->IsExceptionPending());
- return 0;
+ return nullptr;
}
auto destination = reinterpret_cast<jbyte*>(dex_mem_map.get()->Begin());
@@ -273,7 +273,7 @@
jobjectArray dex_elements) {
ScopedUtfChars sourceName(env, javaSourceName);
if (sourceName.c_str() == nullptr) {
- return 0;
+ return nullptr;
}
Runtime* const runtime = Runtime::Current();
diff --git a/runtime/native/dalvik_system_VMDebug.cc b/runtime/native/dalvik_system_VMDebug.cc
index f1e267b..7ac4086 100644
--- a/runtime/native/dalvik_system_VMDebug.cc
+++ b/runtime/native/dalvik_system_VMDebug.cc
@@ -388,7 +388,7 @@
// as PSS, private/shared dirty/shared data are available via
// /proc/<pid>/smaps.
static void VMDebug_getHeapSpaceStats(JNIEnv* env, jclass, jlongArray data) {
- jlong* arr = reinterpret_cast<jlong*>(env->GetPrimitiveArrayCritical(data, 0));
+ jlong* arr = reinterpret_cast<jlong*>(env->GetPrimitiveArrayCritical(data, nullptr));
if (arr == nullptr || env->GetArrayLength(data) < 9) {
return;
}
diff --git a/runtime/native/java_lang_reflect_Constructor.cc b/runtime/native/java_lang_reflect_Constructor.cc
index e54674f..4b4d6e3 100644
--- a/runtime/native/java_lang_reflect_Constructor.cc
+++ b/runtime/native/java_lang_reflect_Constructor.cc
@@ -121,7 +121,7 @@
static jobject Constructor_newInstanceFromSerialization(JNIEnv* env, jclass unused ATTRIBUTE_UNUSED,
jclass ctorClass, jclass allocClass) {
jmethodID ctor = env->GetMethodID(ctorClass, "<init>", "()V");
- DCHECK(ctor != NULL);
+ DCHECK(ctor != nullptr);
return env->NewObject(allocClass, ctor);
}
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index 5f87bf0..4ed26fa 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -550,7 +550,7 @@
const IndexBssMapping* const method_bss_mapping_ = nullptr;
const IndexBssMapping* const type_bss_mapping_ = nullptr;
const IndexBssMapping* const string_bss_mapping_ = nullptr;
- const uint32_t* const oat_class_offsets_pointer_ = 0u;
+ const uint32_t* const oat_class_offsets_pointer_ = nullptr;
TypeLookupTable lookup_table_;
const DexLayoutSections* const dex_layout_sections_ = nullptr;
diff --git a/test/674-hiddenapi/hiddenapi.cc b/test/674-hiddenapi/hiddenapi.cc
index 04c3fbf..96754c3 100644
--- a/test/674-hiddenapi/hiddenapi.cc
+++ b/test/674-hiddenapi/hiddenapi.cc
@@ -63,8 +63,8 @@
static jobject NewInstance(JNIEnv* env, jclass klass) {
jmethodID constructor = env->GetMethodID(klass, "<init>", "()V");
- if (constructor == NULL) {
- return NULL;
+ if (constructor == nullptr) {
+ return nullptr;
}
return env->NewObject(klass, constructor);
}
@@ -74,7 +74,7 @@
ScopedUtfChars utf_name(env, name);
jfieldID field = is_static ? env->GetStaticFieldID(klass, utf_name.c_str(), "I")
: env->GetFieldID(klass, utf_name.c_str(), "I");
- if (field == NULL) {
+ if (field == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -87,7 +87,7 @@
ScopedUtfChars utf_name(env, name);
jfieldID field = is_static ? env->GetStaticFieldID(klass, utf_name.c_str(), "I")
: env->GetFieldID(klass, utf_name.c_str(), "I");
- if (field == NULL) {
+ if (field == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -95,7 +95,7 @@
env->GetStaticIntField(klass, field);
} else {
jobject obj = NewInstance(env, klass);
- if (obj == NULL) {
+ if (obj == nullptr) {
env->ExceptionDescribe();
env->ExceptionClear();
return JNI_FALSE;
@@ -117,7 +117,7 @@
ScopedUtfChars utf_name(env, name);
jfieldID field = is_static ? env->GetStaticFieldID(klass, utf_name.c_str(), "I")
: env->GetFieldID(klass, utf_name.c_str(), "I");
- if (field == NULL) {
+ if (field == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -125,7 +125,7 @@
env->SetStaticIntField(klass, field, 42);
} else {
jobject obj = NewInstance(env, klass);
- if (obj == NULL) {
+ if (obj == nullptr) {
env->ExceptionDescribe();
env->ExceptionClear();
return JNI_FALSE;
@@ -147,7 +147,7 @@
ScopedUtfChars utf_name(env, name);
jmethodID method = is_static ? env->GetStaticMethodID(klass, utf_name.c_str(), "()I")
: env->GetMethodID(klass, utf_name.c_str(), "()I");
- if (method == NULL) {
+ if (method == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -160,7 +160,7 @@
ScopedUtfChars utf_name(env, name);
jmethodID method = is_static ? env->GetStaticMethodID(klass, utf_name.c_str(), "()I")
: env->GetMethodID(klass, utf_name.c_str(), "()I");
- if (method == NULL) {
+ if (method == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -169,7 +169,7 @@
env->CallStaticIntMethodA(klass, method, nullptr);
} else {
jobject obj = NewInstance(env, klass);
- if (obj == NULL) {
+ if (obj == nullptr) {
env->ExceptionDescribe();
env->ExceptionClear();
return JNI_FALSE;
@@ -191,7 +191,7 @@
ScopedUtfChars utf_name(env, name);
jmethodID method = is_static ? env->GetStaticMethodID(klass, utf_name.c_str(), "()I")
: env->GetMethodID(klass, utf_name.c_str(), "()I");
- if (method == NULL) {
+ if (method == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -200,7 +200,7 @@
env->CallStaticIntMethod(klass, method);
} else {
jobject obj = NewInstance(env, klass);
- if (obj == NULL) {
+ if (obj == nullptr) {
env->ExceptionDescribe();
env->ExceptionClear();
return JNI_FALSE;
@@ -224,7 +224,7 @@
JNIEnv* env, jclass, jclass klass, jstring args) {
ScopedUtfChars utf_args(env, args);
jmethodID constructor = env->GetMethodID(klass, "<init>", utf_args.c_str());
- if (constructor == NULL) {
+ if (constructor == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -236,7 +236,7 @@
JNIEnv* env, jclass, jclass klass, jstring args) {
ScopedUtfChars utf_args(env, args);
jmethodID constructor = env->GetMethodID(klass, "<init>", utf_args.c_str());
- if (constructor == NULL) {
+ if (constructor == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
@@ -261,7 +261,7 @@
JNIEnv* env, jclass, jclass klass, jstring args) {
ScopedUtfChars utf_args(env, args);
jmethodID constructor = env->GetMethodID(klass, "<init>", utf_args.c_str());
- if (constructor == NULL) {
+ if (constructor == nullptr) {
env->ExceptionClear();
return JNI_FALSE;
}
diff --git a/tools/jfuzz/jfuzz.cc b/tools/jfuzz/jfuzz.cc
index 60c6275..a97a99c 100644
--- a/tools/jfuzz/jfuzz.cc
+++ b/tools/jfuzz/jfuzz.cc
@@ -1302,7 +1302,7 @@
int32_t main(int32_t argc, char** argv) {
// Time-based seed.
struct timeval tp;
- gettimeofday(&tp, NULL);
+ gettimeofday(&tp, nullptr);
// Defaults.
uint32_t seed = (tp.tv_sec * 1000000 + tp.tv_usec);