[libutils] Modernize codebase by replacing NULL with nullptr

Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
This commit is contained in:
Yi Kong 2018-07-16 18:11:34 -07:00
parent 895acebe94
commit e1731a4f2e
26 changed files with 136 additions and 136 deletions

View file

@ -122,7 +122,7 @@ class Backtrace {
// Tracing a thread in a different process is not supported.
// If map is NULL, then create the map and manage it internally.
// If map is not NULL, the map is still owned by the caller.
static Backtrace* Create(pid_t pid, pid_t tid, BacktraceMap* map = NULL);
static Backtrace* Create(pid_t pid, pid_t tid, BacktraceMap* map = nullptr);
// Create an offline Backtrace object that can be used to do an unwind without a process
// that is still running. By default, information is only cached in the map
@ -145,7 +145,7 @@ class Backtrace {
virtual ~Backtrace();
// Get the current stack trace and store in the backtrace_ structure.
virtual bool Unwind(size_t num_ignore_frames, void* context = NULL) = 0;
virtual bool Unwind(size_t num_ignore_frames, void* context = nullptr) = 0;
static bool Unwind(unwindstack::Regs* regs, BacktraceMap* back_map,
std::vector<backtrace_frame_data_t>* frames, size_t num_ignore_frames,
@ -160,7 +160,7 @@ class Backtrace {
// If the string is empty, then no valid function name was found,
// or the pc is not in any valid map.
virtual std::string GetFunctionName(uint64_t pc, uint64_t* offset,
const backtrace_map_t* map = NULL);
const backtrace_map_t* map = nullptr);
// Fill in the map data associated with the given pc.
virtual void FillInMap(uint64_t pc, backtrace_map_t* map);
@ -185,7 +185,7 @@ class Backtrace {
const backtrace_frame_data_t* GetFrame(size_t frame_num) {
if (frame_num >= frames_.size()) {
return NULL;
return nullptr;
}
return &frames_[frame_num];
}

View file

@ -48,10 +48,10 @@ using namespace android;
// Constructor. Create an empty object.
FileMap::FileMap(void)
: mFileName(NULL),
mBasePtr(NULL),
: mFileName(nullptr),
mBasePtr(nullptr),
mBaseLength(0),
mDataPtr(NULL),
mDataPtr(nullptr),
mDataLength(0)
#if defined(__MINGW32__)
,
@ -69,9 +69,9 @@ FileMap::FileMap(FileMap&& other)
, mFileHandle(other.mFileHandle), mFileMapping(other.mFileMapping)
#endif
{
other.mFileName = NULL;
other.mBasePtr = NULL;
other.mDataPtr = NULL;
other.mFileName = nullptr;
other.mBasePtr = nullptr;
other.mDataPtr = nullptr;
#if defined(__MINGW32__)
other.mFileHandle = INVALID_HANDLE_VALUE;
other.mFileMapping = NULL;
@ -86,9 +86,9 @@ FileMap& FileMap::operator=(FileMap&& other) {
mDataOffset = other.mDataOffset;
mDataPtr = other.mDataPtr;
mDataLength = other.mDataLength;
other.mFileName = NULL;
other.mBasePtr = NULL;
other.mDataPtr = NULL;
other.mFileName = nullptr;
other.mBasePtr = nullptr;
other.mDataPtr = nullptr;
#if defined(__MINGW32__)
mFileHandle = other.mFileHandle;
mFileMapping = other.mFileMapping;
@ -101,7 +101,7 @@ FileMap& FileMap::operator=(FileMap&& other) {
// Destructor.
FileMap::~FileMap(void)
{
if (mFileName != NULL) {
if (mFileName != nullptr) {
free(mFileName);
}
#if defined(__MINGW32__)
@ -196,7 +196,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le
if (!readOnly)
prot |= PROT_WRITE;
ptr = mmap(NULL, adjLength, prot, flags, fd, adjOffset);
ptr = mmap(nullptr, adjLength, prot, flags, fd, adjOffset);
if (ptr == MAP_FAILED) {
ALOGE("mmap(%lld,%zu) failed: %s\n",
(long long)adjOffset, adjLength, strerror(errno));
@ -205,7 +205,7 @@ bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t le
mBasePtr = ptr;
#endif // !defined(__MINGW32__)
mFileName = origFileName != NULL ? strdup(origFileName) : NULL;
mFileName = origFileName != nullptr ? strdup(origFileName) : nullptr;
mBaseLength = adjLength;
mDataOffset = offset;
mDataPtr = (char*) mBasePtr + adjust;

View file

@ -29,7 +29,7 @@ WeakMessageHandler::~WeakMessageHandler() {
void WeakMessageHandler::handleMessage(const Message& message) {
sp<MessageHandler> handler = mHandler.promote();
if (handler != NULL) {
if (handler != nullptr) {
handler->handleMessage(message);
}
}
@ -87,7 +87,7 @@ void Looper::initTLSKey() {
void Looper::threadDestructor(void *st) {
Looper* const self = static_cast<Looper*>(st);
if (self != NULL) {
if (self != nullptr) {
self->decStrong((void*)threadDestructor);
}
}
@ -95,13 +95,13 @@ void Looper::threadDestructor(void *st) {
void Looper::setForThread(const sp<Looper>& looper) {
sp<Looper> old = getForThread(); // also has side-effect of initializing TLS
if (looper != NULL) {
if (looper != nullptr) {
looper->incStrong((void*)threadDestructor);
}
pthread_setspecific(gTLSKey, looper.get());
if (old != NULL) {
if (old != nullptr) {
old->decStrong((void*)threadDestructor);
}
}
@ -116,7 +116,7 @@ sp<Looper> Looper::getForThread() {
sp<Looper> Looper::prepare(int opts) {
bool allowNonCallbacks = opts & PREPARE_ALLOW_NON_CALLBACKS;
sp<Looper> looper = Looper::getForThread();
if (looper == NULL) {
if (looper == nullptr) {
looper = new Looper(allowNonCallbacks);
Looper::setForThread(looper);
}
@ -190,9 +190,9 @@ int Looper::pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outDa
"fd=%d, events=0x%x, data=%p",
this, ident, fd, events, data);
#endif
if (outFd != NULL) *outFd = fd;
if (outEvents != NULL) *outEvents = events;
if (outData != NULL) *outData = data;
if (outFd != nullptr) *outFd = fd;
if (outEvents != nullptr) *outEvents = events;
if (outData != nullptr) *outData = data;
return ident;
}
}
@ -201,9 +201,9 @@ int Looper::pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outDa
#if DEBUG_POLL_AND_WAKE
ALOGD("%p ~ pollOnce - returning result %d", this, result);
#endif
if (outFd != NULL) *outFd = 0;
if (outEvents != NULL) *outEvents = 0;
if (outData != NULL) *outData = NULL;
if (outFd != nullptr) *outFd = 0;
if (outEvents != nullptr) *outEvents = 0;
if (outData != nullptr) *outData = nullptr;
return result;
}
@ -427,7 +427,7 @@ void Looper::pushResponse(int events, const Request& request) {
}
int Looper::addFd(int fd, int ident, int events, Looper_callbackFunc callback, void* data) {
return addFd(fd, ident, events, callback ? new SimpleLooperCallback(callback) : NULL, data);
return addFd(fd, ident, events, callback ? new SimpleLooperCallback(callback) : nullptr, data);
}
int Looper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callback, void* data) {
@ -542,7 +542,7 @@ int Looper::removeFd(int fd, int seq) {
// updating the epoll set so that we avoid accidentally leaking callbacks.
mRequests.removeItemsAt(requestIndex);
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, NULL);
int epollResult = epoll_ctl(mEpollFd, EPOLL_CTL_DEL, fd, nullptr);
if (epollResult < 0) {
if (seq != -1 && (errno == EBADF || errno == ENOENT)) {
// Tolerate EBADF or ENOENT when the sequence number is known because it

View file

@ -20,7 +20,7 @@
namespace android {
sp<NativeHandle> NativeHandle::create(native_handle_t* handle, bool ownsHandle) {
return handle ? new NativeHandle(handle, ownsHandle) : NULL;
return handle ? new NativeHandle(handle, ownsHandle) : nullptr;
}
NativeHandle::NativeHandle(native_handle_t* handle, bool ownsHandle)

View file

@ -73,7 +73,7 @@ LogPrinter::LogPrinter(const char* logtag,
}
void LogPrinter::printLine(const char* string) {
if (string == NULL) {
if (string == nullptr) {
ALOGW("%s: NULL string passed in", __FUNCTION__);
return;
}
@ -107,7 +107,7 @@ FdPrinter::FdPrinter(int fd, unsigned int indent, const char* prefix) :
}
void FdPrinter::printLine(const char* string) {
if (string == NULL) {
if (string == nullptr) {
ALOGW("%s: NULL string passed in", __FUNCTION__);
return;
} else if (mFd < 0) {
@ -127,16 +127,16 @@ String8Printer::String8Printer(String8* target, const char* prefix) :
mTarget(target),
mPrefix(prefix ?: "") {
if (target == NULL) {
if (target == nullptr) {
ALOGW("%s: Target string was NULL", __FUNCTION__);
}
}
void String8Printer::printLine(const char* string) {
if (string == NULL) {
if (string == nullptr) {
ALOGW("%s: NULL string passed in", __FUNCTION__);
return;
} else if (mTarget == NULL) {
} else if (mTarget == nullptr) {
ALOGW("%s: Target string was NULL", __FUNCTION__);
return;
}

View file

@ -42,14 +42,14 @@ static const char* PATH_THREAD_NAME = "/proc/self/task/%d/comm";
static const char* PATH_SELF_TASK = "/proc/self/task";
static void dumpProcessHeader(Printer& printer, pid_t pid, const char* timeStr) {
if (timeStr == NULL) {
if (timeStr == nullptr) {
ALOGW("%s: timeStr was NULL", __FUNCTION__);
return;
}
char path[PATH_MAX];
char procNameBuf[MAX_PROC_PATH];
char* procName = NULL;
char* procName = nullptr;
FILE* fp;
snprintf(path, sizeof(path), "/proc/%d/cmdline", pid);
@ -76,7 +76,7 @@ static void dumpProcessFooter(Printer& printer, pid_t pid) {
static String8 getThreadName(pid_t tid) {
char path[PATH_MAX];
char* procName = NULL;
char* procName = nullptr;
char procNameBuf[MAX_PROC_PATH];
FILE* fp;
@ -88,7 +88,7 @@ static String8 getThreadName(pid_t tid) {
ALOGE("%s: Failed to open %s", __FUNCTION__, path);
}
if (procName == NULL) {
if (procName == nullptr) {
// Reading /proc/self/task/%d/comm failed due to a race
return String8::format("[err-unknown-tid-%d]", tid);
}
@ -128,7 +128,7 @@ void ProcessCallStack::clear() {
void ProcessCallStack::update() {
std::unique_ptr<DIR, decltype(&closedir)> dp(opendir(PATH_SELF_TASK), closedir);
if (dp == NULL) {
if (dp == nullptr) {
ALOGE("%s: Failed to update the process's call stacks: %s",
__FUNCTION__, strerror(errno));
return;
@ -140,7 +140,7 @@ void ProcessCallStack::update() {
// Get current time.
{
time_t t = time(NULL);
time_t t = time(nullptr);
struct tm tm;
localtime_r(&t, &tm);
@ -152,7 +152,7 @@ void ProcessCallStack::update() {
* - Read every file in directory => get every tid
*/
dirent* ep;
while ((ep = readdir(dp.get())) != NULL) {
while ((ep = readdir(dp.get())) != nullptr) {
pid_t tid = -1;
sscanf(ep->d_name, "%d", &tid);

View file

@ -112,7 +112,7 @@ void PropertyMap::addAll(const PropertyMap* map) {
}
status_t PropertyMap::load(const String8& filename, PropertyMap** outMap) {
*outMap = NULL;
*outMap = nullptr;
Tokenizer* tokenizer;
status_t status = Tokenizer::open(filename, &tokenizer);

View file

@ -712,7 +712,7 @@ RefBase::~RefBase()
delete mRefs;
}
// For debugging purposes, clear mRefs. Ineffective against outstanding wp's.
const_cast<weakref_impl*&>(mRefs) = NULL;
const_cast<weakref_impl*&>(mRefs) = nullptr;
}
void RefBase::extendObjectLifetime(int32_t mode)

View file

@ -75,7 +75,7 @@ SharedBuffer* SharedBuffer::editResize(size_t newSize) const
"Invalid buffer size %zu", newSize);
buf = (SharedBuffer*)realloc(buf, sizeof(SharedBuffer) + newSize);
if (buf != NULL) {
if (buf != nullptr) {
buf->mSize = newSize;
return buf;
}
@ -94,7 +94,7 @@ SharedBuffer* SharedBuffer::attemptEdit() const
if (onlyOwner()) {
return const_cast<SharedBuffer*>(this);
}
return 0;
return nullptr;
}
SharedBuffer* SharedBuffer::reset(size_t new_size) const

View file

@ -124,11 +124,11 @@ size_t SharedBuffer::size() const {
}
SharedBuffer* SharedBuffer::bufferFromData(void* data) {
return data ? static_cast<SharedBuffer *>(data)-1 : 0;
return data ? static_cast<SharedBuffer *>(data)-1 : nullptr;
}
const SharedBuffer* SharedBuffer::bufferFromData(const void* data) {
return data ? static_cast<const SharedBuffer *>(data)-1 : 0;
return data ? static_cast<const SharedBuffer *>(data)-1 : nullptr;
}
size_t SharedBuffer::sizeFromData(const void* data) {

View file

@ -74,7 +74,7 @@ String16::String16()
}
String16::String16(StaticLinkage)
: mString(0)
: mString(nullptr)
{
// this constructor is used when we can't rely on the static-initializers
// having run. In this case we always allocate an empty string. It's less
@ -336,7 +336,7 @@ status_t String16::makeLower()
{
const size_t N = size();
const char16_t* str = string();
char16_t* edit = NULL;
char16_t* edit = nullptr;
for (size_t i=0; i<N; i++) {
const char16_t v = str[i];
if (v >= 'A' && v <= 'Z') {
@ -358,7 +358,7 @@ status_t String16::replaceAll(char16_t replaceThis, char16_t withThis)
{
const size_t N = size();
const char16_t* str = string();
char16_t* edit = NULL;
char16_t* edit = nullptr;
for (size_t i=0; i<N; i++) {
if (str[i] == replaceThis) {
if (!edit) {

View file

@ -58,7 +58,7 @@ static char* allocFromUTF8(const char* in, size_t len)
{
if (len > 0) {
if (len == SIZE_MAX) {
return NULL;
return nullptr;
}
SharedBuffer* buf = SharedBuffer::alloc(len+1);
ALOG_ASSERT(buf, "Unable to allocate shared buffer");
@ -68,7 +68,7 @@ static char* allocFromUTF8(const char* in, size_t len)
str[len] = 0;
return str;
}
return NULL;
return nullptr;
}
return getEmptyString();
@ -126,7 +126,7 @@ String8::String8()
}
String8::String8(StaticLinkage)
: mString(0)
: mString(nullptr)
{
// this constructor is used when we can't rely on the static-initializers
// having run. In this case we always allocate an empty string. It's less
@ -147,7 +147,7 @@ String8::String8(const String8& o)
String8::String8(const char* o)
: mString(allocFromUTF8(o, strlen(o)))
{
if (mString == NULL) {
if (mString == nullptr) {
mString = getEmptyString();
}
}
@ -155,7 +155,7 @@ String8::String8(const char* o)
String8::String8(const char* o, size_t len)
: mString(allocFromUTF8(o, len))
{
if (mString == NULL) {
if (mString == nullptr) {
mString = getEmptyString();
}
}
@ -319,7 +319,7 @@ status_t String8::appendFormatV(const char* fmt, va_list args)
* second vsnprintf access undefined args.
*/
va_copy(tmp_args, args);
n = vsnprintf(NULL, 0, fmt, tmp_args);
n = vsnprintf(nullptr, 0, fmt, tmp_args);
va_end(tmp_args);
if (n != 0) {
@ -360,7 +360,7 @@ char* String8::lockBuffer(size_t size)
mString = str;
return str;
}
return NULL;
return nullptr;
}
void String8::unlockBuffer()
@ -512,7 +512,7 @@ String8 String8::getPathLeaf(void) const
const char*const buf = mString;
cp = strrchr(buf, OS_PATH_SEPARATOR);
if (cp == NULL)
if (cp == nullptr)
return String8(*this);
else
return String8(cp+1);
@ -524,7 +524,7 @@ String8 String8::getPathDir(void) const
const char*const str = mString;
cp = strrchr(str, OS_PATH_SEPARATOR);
if (cp == NULL)
if (cp == nullptr)
return String8("");
else
return String8(str, cp - str);
@ -543,7 +543,7 @@ String8 String8::walkPath(String8* outRemains) const
cp = strchr(buf, OS_PATH_SEPARATOR);
}
if (cp == NULL) {
if (cp == nullptr) {
String8 res = buf != str ? String8(buf) : *this;
if (outRemains) *outRemains = String8("");
return res;
@ -567,15 +567,15 @@ char* String8::find_extension(void) const
// only look at the filename
lastSlash = strrchr(str, OS_PATH_SEPARATOR);
if (lastSlash == NULL)
if (lastSlash == nullptr)
lastSlash = str;
else
lastSlash++;
// find the last dot
lastDot = strrchr(lastSlash, '.');
if (lastDot == NULL)
return NULL;
if (lastDot == nullptr)
return nullptr;
// looks good, ship it
return const_cast<char*>(lastDot);
@ -586,7 +586,7 @@ String8 String8::getPathExtension(void) const
char* ext;
ext = find_extension();
if (ext != NULL)
if (ext != nullptr)
return String8(ext);
else
return String8("");
@ -598,7 +598,7 @@ String8 String8::getBasePath(void) const
const char* const str = mString;
ext = find_extension();
if (ext == NULL)
if (ext == nullptr)
return String8(*this);
else
return String8(str, ext - str);

View file

@ -163,7 +163,7 @@ int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
// Note that *threadID is directly available to the parent only, as it is
// assigned after the child starts. Use memory barrier / lock if the child
// or other threads also need access.
if (threadId != NULL) {
if (threadId != nullptr) {
*threadId = (android_thread_id_t)thread; // XXX: this is not portable
}
return 1;
@ -768,7 +768,7 @@ int Thread::_threadLoop(void* user)
strong.clear();
// And immediately, re-acquire a strong reference for the next loop
strong = weak.promote();
} while(strong != 0);
} while(strong != nullptr);
return 0;
}

View file

@ -45,7 +45,7 @@ nsecs_t systemTime(int /*clock*/)
// is windows.
struct timeval t;
t.tv_sec = t.tv_usec = 0;
gettimeofday(&t, NULL);
gettimeofday(&t, nullptr);
return nsecs_t(t.tv_sec)*1000000000LL + nsecs_t(t.tv_usec)*1000LL;
}
#endif

View file

@ -28,7 +28,7 @@
namespace android {
static inline bool isDelimiter(char ch, const char* delimiters) {
return strchr(delimiters, ch) != NULL;
return strchr(delimiters, ch) != nullptr;
}
Tokenizer::Tokenizer(const String8& filename, FileMap* fileMap, char* buffer,
@ -46,7 +46,7 @@ Tokenizer::~Tokenizer() {
}
status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
*outTokenizer = NULL;
*outTokenizer = nullptr;
int result = NO_ERROR;
int fd = ::open(filename.string(), O_RDONLY);
@ -64,12 +64,12 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
FileMap* fileMap = new FileMap();
bool ownBuffer = false;
char* buffer;
if (fileMap->create(NULL, fd, 0, length, true)) {
if (fileMap->create(nullptr, fd, 0, length, true)) {
fileMap->advise(FileMap::SEQUENTIAL);
buffer = static_cast<char*>(fileMap->getDataPtr());
} else {
delete fileMap;
fileMap = NULL;
fileMap = nullptr;
// Fall back to reading into a buffer since we can't mmap files in sysfs.
// The length we obtained from stat is wrong too (it will always be 4096)
@ -81,7 +81,7 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
result = -errno;
ALOGE("Error reading file '%s': %s", filename.string(), strerror(errno));
delete[] buffer;
buffer = NULL;
buffer = nullptr;
} else {
length = size_t(nrd);
}
@ -98,7 +98,7 @@ status_t Tokenizer::open(const String8& filename, Tokenizer** outTokenizer) {
status_t Tokenizer::fromContents(const String8& filename,
const char* contents, Tokenizer** outTokenizer) {
*outTokenizer = new Tokenizer(filename, NULL,
*outTokenizer = new Tokenizer(filename, nullptr,
const_cast<char*>(contents), false, strlen(contents));
return OK;
}

View file

@ -159,7 +159,7 @@ int32_t utf32_from_utf8_at(const char *src, size_t src_len, size_t index, size_t
return -1;
}
size_t dummy_index;
if (next_index == NULL) {
if (next_index == nullptr) {
next_index = &dummy_index;
}
size_t num_read;
@ -173,7 +173,7 @@ int32_t utf32_from_utf8_at(const char *src, size_t src_len, size_t index, size_t
ssize_t utf32_to_utf8_length(const char32_t *src, size_t src_len)
{
if (src == NULL || src_len == 0) {
if (src == nullptr || src_len == 0) {
return -1;
}
@ -195,7 +195,7 @@ ssize_t utf32_to_utf8_length(const char32_t *src, size_t src_len)
void utf32_to_utf8(const char32_t* src, size_t src_len, char* dst, size_t dst_len)
{
if (src == NULL || src_len == 0 || dst == NULL) {
if (src == nullptr || src_len == 0 || dst == nullptr) {
return;
}
@ -363,7 +363,7 @@ int strzcmp16_h_n(const char16_t *s1H, size_t n1, const char16_t *s2N, size_t n2
void utf16_to_utf8(const char16_t* src, size_t src_len, char* dst, size_t dst_len)
{
if (src == NULL || src_len == 0 || dst == NULL) {
if (src == nullptr || src_len == 0 || dst == nullptr) {
return;
}
@ -440,7 +440,7 @@ ssize_t utf8_length(const char *src)
ssize_t utf16_to_utf8_length(const char16_t *src, size_t src_len)
{
if (src == NULL || src_len == 0) {
if (src == nullptr || src_len == 0) {
return -1;
}
@ -490,7 +490,7 @@ static inline void utf8_shift_and_mask(uint32_t* codePoint, const uint8_t byte)
size_t utf8_to_utf32_length(const char *src, size_t src_len)
{
if (src == NULL || src_len == 0) {
if (src == nullptr || src_len == 0) {
return 0;
}
size_t ret = 0;
@ -515,7 +515,7 @@ size_t utf8_to_utf32_length(const char *src, size_t src_len)
void utf8_to_utf32(const char* src, size_t src_len, char32_t* dst)
{
if (src == NULL || src_len == 0 || dst == NULL) {
if (src == nullptr || src_len == 0 || dst == nullptr) {
return;
}

View file

@ -44,7 +44,7 @@ static inline size_t max(size_t a, size_t b) {
// ----------------------------------------------------------------------------
VectorImpl::VectorImpl(size_t itemSize, uint32_t flags)
: mStorage(0), mCount(0), mFlags(flags), mItemSize(itemSize)
: mStorage(nullptr), mCount(0), mFlags(flags), mItemSize(itemSize)
{
}
@ -77,7 +77,7 @@ VectorImpl& VectorImpl::operator = (const VectorImpl& rhs)
mCount = rhs.mCount;
SharedBuffer::bufferFromData(mStorage)->acquire();
} else {
mStorage = 0;
mStorage = nullptr;
mCount = 0;
}
}
@ -89,14 +89,14 @@ void* VectorImpl::editArrayImpl()
if (mStorage) {
const SharedBuffer* sb = SharedBuffer::bufferFromData(mStorage);
SharedBuffer* editable = sb->attemptEdit();
if (editable == 0) {
if (editable == nullptr) {
// If we're here, we're not the only owner of the buffer.
// We must make a copy of it.
editable = SharedBuffer::alloc(sb->size());
// Fail instead of returning a pointer to storage that's not
// editable. Otherwise we'd be editing the contents of a buffer
// for which we're not the only owner, which is undefined behaviour.
LOG_ALWAYS_FATAL_IF(editable == NULL);
LOG_ALWAYS_FATAL_IF(editable == nullptr);
_do_copy(editable->data(), mStorage, mCount);
release_storage();
mStorage = editable->data();
@ -141,7 +141,7 @@ ssize_t VectorImpl::appendArray(const void* array, size_t length)
ssize_t VectorImpl::insertAt(size_t index, size_t numItems)
{
return insertAt(0, index, numItems);
return insertAt(nullptr, index, numItems);
}
ssize_t VectorImpl::insertAt(const void* item, size_t index, size_t numItems)
@ -177,7 +177,7 @@ status_t VectorImpl::sort(VectorImpl::compar_r_t cmp, void* state)
const ssize_t count = size();
if (count > 1) {
void* array = const_cast<void*>(arrayImpl());
void* temp = 0;
void* temp = nullptr;
ssize_t i = 1;
while (i < count) {
void* item = reinterpret_cast<char*>(array) + mItemSize*(i);
@ -205,7 +205,7 @@ status_t VectorImpl::sort(VectorImpl::compar_r_t cmp, void* state)
_do_copy(next, curr, 1);
next = curr;
--j;
curr = NULL;
curr = nullptr;
if (j >= 0) {
curr = reinterpret_cast<char*>(array) + mItemSize*(j);
}
@ -233,7 +233,7 @@ void VectorImpl::pop()
void VectorImpl::push()
{
push(0);
push(nullptr);
}
void VectorImpl::push(const void* item)
@ -243,7 +243,7 @@ void VectorImpl::push(const void* item)
ssize_t VectorImpl::add()
{
return add(0);
return add(nullptr);
}
ssize_t VectorImpl::add(const void* item)
@ -253,7 +253,7 @@ ssize_t VectorImpl::add(const void* item)
ssize_t VectorImpl::replaceAt(size_t index)
{
return replaceAt(0, index);
return replaceAt(nullptr, index);
}
ssize_t VectorImpl::replaceAt(const void* prototype, size_t index)
@ -267,10 +267,10 @@ ssize_t VectorImpl::replaceAt(const void* prototype, size_t index)
void* item = editItemLocation(index);
if (item != prototype) {
if (item == 0)
if (item == nullptr)
return NO_MEMORY;
_do_destroy(item, 1);
if (prototype == 0) {
if (prototype == nullptr) {
_do_construct(item, 1);
} else {
_do_copy(item, prototype, 1);
@ -294,7 +294,7 @@ ssize_t VectorImpl::removeItemsAt(size_t index, size_t count)
void VectorImpl::finish_vector()
{
release_storage();
mStorage = 0;
mStorage = nullptr;
mCount = 0;
}
@ -315,7 +315,7 @@ void* VectorImpl::editItemLocation(size_t index)
return reinterpret_cast<char*>(buffer) + index*mItemSize;
}
}
return 0;
return nullptr;
}
const void* VectorImpl::itemLocation(size_t index) const
@ -330,7 +330,7 @@ const void* VectorImpl::itemLocation(size_t index) const
return reinterpret_cast<const char*>(buffer) + index*mItemSize;
}
}
return 0;
return nullptr;
}
ssize_t VectorImpl::setCapacity(size_t new_capacity)
@ -418,7 +418,7 @@ void* VectorImpl::_grow(size_t where, size_t amount)
if (sb) {
mStorage = sb->data();
} else {
return NULL;
return nullptr;
}
} else {
SharedBuffer* sb = SharedBuffer::alloc(new_alloc_size);
@ -435,7 +435,7 @@ void* VectorImpl::_grow(size_t where, size_t amount)
release_storage();
mStorage = const_cast<void*>(array);
} else {
return NULL;
return nullptr;
}
}
} else {

View file

@ -124,7 +124,7 @@ inline status_t Condition::waitRelative(Mutex& mutex, nsecs_t reltime) {
#else // __APPLE__
// Apple doesn't support POSIX clocks.
struct timeval t;
gettimeofday(&t, NULL);
gettimeofday(&t, nullptr);
ts.tv_sec = t.tv_sec;
ts.tv_nsec = t.tv_usec*1000;
#endif

View file

@ -71,7 +71,7 @@ private:
Entry* parent;
Entry* child;
Entry(TKey _key, TValue _value) : key(_key), value(_value), parent(NULL), child(NULL) {
Entry(TKey _key, TValue _value) : key(_key), value(_value), parent(nullptr), child(nullptr) {
}
const TKey& getKey() const final { return key; }
};
@ -162,9 +162,9 @@ public:
template <typename TKey, typename TValue>
LruCache<TKey, TValue>::LruCache(uint32_t maxCapacity)
: mSet(new LruCacheSet())
, mListener(NULL)
, mOldest(NULL)
, mYoungest(NULL)
, mListener(nullptr)
, mOldest(nullptr)
, mYoungest(nullptr)
, mMaxCapacity(maxCapacity)
, mNullValue(0) {
mSet->max_load_factor(1.0);
@ -236,7 +236,7 @@ bool LruCache<TKey, TValue>::remove(const TKey& key) {
template <typename TKey, typename TValue>
bool LruCache<TKey, TValue>::removeOldest() {
if (mOldest != NULL) {
if (mOldest != nullptr) {
return remove(mOldest->key);
// TODO: should probably abort if false
}
@ -254,12 +254,12 @@ const TValue& LruCache<TKey, TValue>::peekOldestValue() {
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::clear() {
if (mListener) {
for (Entry* p = mOldest; p != NULL; p = p->child) {
for (Entry* p = mOldest; p != nullptr; p = p->child) {
(*mListener)(p->key, p->value);
}
}
mYoungest = NULL;
mOldest = NULL;
mYoungest = nullptr;
mOldest = nullptr;
for (auto entry : *mSet.get()) {
delete entry;
}
@ -268,7 +268,7 @@ void LruCache<TKey, TValue>::clear() {
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::attachToCache(Entry& entry) {
if (mYoungest == NULL) {
if (mYoungest == nullptr) {
mYoungest = mOldest = &entry;
} else {
entry.parent = mYoungest;
@ -279,19 +279,19 @@ void LruCache<TKey, TValue>::attachToCache(Entry& entry) {
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::detachFromCache(Entry& entry) {
if (entry.parent != NULL) {
if (entry.parent != nullptr) {
entry.parent->child = entry.child;
} else {
mOldest = entry.child;
}
if (entry.child != NULL) {
if (entry.child != nullptr) {
entry.child->parent = entry.parent;
} else {
mYoungest = entry.parent;
}
entry.parent = NULL;
entry.child = NULL;
entry.parent = nullptr;
entry.child = nullptr;
}
}

View file

@ -45,7 +45,7 @@ public:
// (Note that the default ALOG behavior is to ignore blank lines)
LogPrinter(const char* logtag,
android_LogPriority priority = ANDROID_LOG_DEBUG,
const char* prefix = 0,
const char* prefix = nullptr,
bool ignoreBlankLines = false);
// Print the specified line to logcat. No \n at the end is necessary.
@ -66,7 +66,7 @@ public:
// Create a printer using the specified file descriptor.
// - Each line will be prefixed with 'indent' number of blank spaces.
// - In addition, each line will be prefixed with the 'prefix' string.
FdPrinter(int fd, unsigned int indent = 0, const char* prefix = 0);
FdPrinter(int fd, unsigned int indent = 0, const char* prefix = nullptr);
// Print the specified line to the file descriptor. \n is appended automatically.
virtual void printLine(const char* string);
@ -90,7 +90,7 @@ public:
// Create a printer using the specified String8 as the target.
// - In addition, each line will be prefixed with the 'prefix' string.
// - target's memory lifetime must be a superset of this String8Printer.
String8Printer(String8* target, const char* prefix = 0);
String8Printer(String8* target, const char* prefix = nullptr);
// Append the specified line to the String8. \n is appended automatically.
virtual void printLine(const char* string);

View file

@ -43,13 +43,13 @@ public:
// Print all stack traces to the log using the supplied logtag.
void log(const char* logtag, android_LogPriority priority = ANDROID_LOG_DEBUG,
const char* prefix = 0) const;
const char* prefix = nullptr) const;
// Dump all stack traces to the specified file descriptor.
void dump(int fd, int indent = 0, const char* prefix = 0) const;
void dump(int fd, int indent = 0, const char* prefix = nullptr) const;
// Return a string (possibly very long) containing all the stack traces.
String8 toString(const char* prefix = 0) const;
String8 toString(const char* prefix = nullptr) const;
// Dump a serialized representation of all the stack traces to the specified printer.
void print(Printer& printer) const;

View file

@ -563,7 +563,7 @@ template<typename T> template<typename U>
wp<T>& wp<T>::operator = (const sp<U>& other)
{
weakref_type* newRefs =
other != NULL ? other->createWeak(this) : 0;
other != nullptr ? other->createWeak(this) : 0;
U* otherPtr(other.m_ptr);
if (m_ptr) m_refs->decWeak(this);
m_ptr = otherPtr;

View file

@ -41,13 +41,13 @@ struct sysprop_change_callback_info {
#if !defined(_WIN32)
static pthread_mutex_t gSyspropMutex = PTHREAD_MUTEX_INITIALIZER;
static Vector<sysprop_change_callback_info>* gSyspropList = NULL;
static Vector<sysprop_change_callback_info>* gSyspropList = nullptr;
#endif
#if !defined(_WIN32)
void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
pthread_mutex_lock(&gSyspropMutex);
if (gSyspropList == NULL) {
if (gSyspropList == nullptr) {
gSyspropList = new Vector<sysprop_change_callback_info>();
}
sysprop_change_callback_info info;
@ -103,7 +103,7 @@ void do_report_sysprop_change() {
#if !defined(_WIN32)
pthread_mutex_lock(&gSyspropMutex);
Vector<sysprop_change_callback_info> listeners;
if (gSyspropList != NULL) {
if (gSyspropList != nullptr) {
listeners = *gSyspropList;
}
pthread_mutex_unlock(&gSyspropMutex);

View file

@ -339,7 +339,7 @@ TEST_F(LooperTest, PollOnce_WhenNonCallbackFdIsSignalled_ReturnsIdent) {
Pipe pipe;
pipe.writeSignal();
mLooper->addFd(pipe.receiveFd, expectedIdent, Looper::EVENT_INPUT, NULL, expectedData);
mLooper->addFd(pipe.receiveFd, expectedIdent, Looper::EVENT_INPUT, nullptr, expectedData);
StopWatch stopWatch("pollOnce");
int fd;
@ -364,7 +364,7 @@ TEST_F(LooperTest, PollOnce_WhenNonCallbackFdIsSignalled_ReturnsIdent) {
TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) {
Pipe pipe;
int result = mLooper->addFd(pipe.receiveFd, 0, Looper::EVENT_INPUT, NULL, NULL);
int result = mLooper->addFd(pipe.receiveFd, 0, Looper::EVENT_INPUT, nullptr, nullptr);
EXPECT_EQ(1, result)
<< "addFd should return 1 because FD was added";
@ -372,7 +372,7 @@ TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) {
TEST_F(LooperTest, AddFd_WhenIdentIsNegativeAndCallbackIsNull_ReturnsError) {
Pipe pipe;
int result = mLooper->addFd(pipe.receiveFd, -1, Looper::EVENT_INPUT, NULL, NULL);
int result = mLooper->addFd(pipe.receiveFd, -1, Looper::EVENT_INPUT, nullptr, nullptr);
EXPECT_EQ(-1, result)
<< "addFd should return -1 because arguments were invalid";
@ -381,7 +381,7 @@ TEST_F(LooperTest, AddFd_WhenIdentIsNegativeAndCallbackIsNull_ReturnsError) {
TEST_F(LooperTest, AddFd_WhenNoCallbackAndAllowNonCallbacksIsFalse_ReturnsError) {
Pipe pipe;
sp<Looper> looper = new Looper(false /*allowNonCallbacks*/);
int result = looper->addFd(pipe.receiveFd, 0, 0, NULL, NULL);
int result = looper->addFd(pipe.receiveFd, 0, 0, nullptr, nullptr);
EXPECT_EQ(-1, result)
<< "addFd should return -1 because arguments were invalid";

View file

@ -110,7 +110,7 @@ template<> inline android::hash_t hash_type(const KeyFailsOnCopy& value) {
class EntryRemovedCallback : public OnEntryRemoved<SimpleKey, StringValue> {
public:
EntryRemovedCallback() : callbackCount(0), lastKey(-1), lastValue(NULL) { }
EntryRemovedCallback() : callbackCount(0), lastKey(-1), lastValue(nullptr) { }
~EntryRemovedCallback() {}
void operator()(SimpleKey& k, StringValue& v) {
callbackCount += 1;
@ -153,7 +153,7 @@ protected:
TEST_F(LruCacheTest, Empty) {
LruCache<SimpleKey, StringValue> cache(100);
EXPECT_EQ(NULL, cache.get(0));
EXPECT_EQ(nullptr, cache.get(0));
EXPECT_EQ(0u, cache.size());
}
@ -175,7 +175,7 @@ TEST_F(LruCacheTest, MaxCapacity) {
cache.put(1, "one");
cache.put(2, "two");
cache.put(3, "three");
EXPECT_EQ(NULL, cache.get(1));
EXPECT_EQ(nullptr, cache.get(1));
EXPECT_STREQ("two", cache.get(2));
EXPECT_STREQ("three", cache.get(3));
EXPECT_EQ(2u, cache.size());
@ -188,7 +188,7 @@ TEST_F(LruCacheTest, RemoveLru) {
cache.put(2, "two");
cache.put(3, "three");
cache.removeOldest();
EXPECT_EQ(NULL, cache.get(1));
EXPECT_EQ(nullptr, cache.get(1));
EXPECT_STREQ("two", cache.get(2));
EXPECT_STREQ("three", cache.get(3));
EXPECT_EQ(2u, cache.size());
@ -203,7 +203,7 @@ TEST_F(LruCacheTest, GetUpdatesLru) {
EXPECT_STREQ("one", cache.get(1));
cache.removeOldest();
EXPECT_STREQ("one", cache.get(1));
EXPECT_EQ(NULL, cache.get(2));
EXPECT_EQ(nullptr, cache.get(2));
EXPECT_STREQ("three", cache.get(3));
EXPECT_EQ(2u, cache.size());
}
@ -230,7 +230,7 @@ TEST_F(LruCacheTest, StressTest) {
int index = random() % kNumKeys;
uint32_t key = hash_int(index);
const char *val = cache.get(key);
if (val != NULL) {
if (val != nullptr) {
EXPECT_EQ(strings[index], val);
hitCount++;
} else {

View file

@ -98,7 +98,7 @@ TEST_F(VectorTest, _grow_OverflowSize) {
// Checks that the size calculation (not the capacity calculation) doesn't
// overflow : the size here will be (1 + SIZE_MAX).
EXPECT_DEATH(vector.insertArrayAt(NULL, 0, SIZE_MAX), "new_size overflow");
EXPECT_DEATH(vector.insertArrayAt(nullptr, 0, SIZE_MAX), "new_size overflow");
}
TEST_F(VectorTest, _grow_OverflowCapacityDoubling) {
@ -106,14 +106,14 @@ TEST_F(VectorTest, _grow_OverflowCapacityDoubling) {
// This should fail because the calculated capacity will overflow even though
// the size of the vector doesn't.
EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX - 1)), "new_capacity overflow");
EXPECT_DEATH(vector.insertArrayAt(nullptr, 0, (SIZE_MAX - 1)), "new_capacity overflow");
}
TEST_F(VectorTest, _grow_OverflowBufferAlloc) {
Vector<int> vector;
// This should fail because the capacity * sizeof(int) overflows, even
// though the capacity itself doesn't.
EXPECT_DEATH(vector.insertArrayAt(NULL, 0, (SIZE_MAX / 2)), "new_alloc_size overflow");
EXPECT_DEATH(vector.insertArrayAt(nullptr, 0, (SIZE_MAX / 2)), "new_alloc_size overflow");
}
TEST_F(VectorTest, editArray_Shared) {