Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
diff --git a/libc/stdio/printf_common.h b/libc/stdio/printf_common.h
index 85c91de..9b7c329 100644
--- a/libc/stdio/printf_common.h
+++ b/libc/stdio/printf_common.h
@@ -535,7 +535,7 @@
*/
if (tablemax >= STATIC_ARG_TBL_SIZE) {
*argtablesiz = sizeof(union arg) * (tablemax + 1);
- *argtable = static_cast<arg*>(mmap(NULL, *argtablesiz,
+ *argtable = static_cast<arg*>(mmap(nullptr, *argtablesiz,
PROT_WRITE | PROT_READ,
MAP_ANON | MAP_PRIVATE, -1, 0));
if (*argtable == MAP_FAILED) return -1;
@@ -629,9 +629,9 @@
ret = -1;
finish:
- if (typetable != NULL && typetable != stattypetable) {
+ if (typetable != nullptr && typetable != stattypetable) {
munmap(typetable, *argtablesiz);
- typetable = NULL;
+ typetable = nullptr;
}
return (ret);
}
@@ -646,13 +646,13 @@
if (new_size < getpagesize()) new_size = getpagesize();
if (*tablesize == STATIC_ARG_TBL_SIZE) {
- *typetable = static_cast<unsigned char*>(mmap(NULL, new_size,
+ *typetable = static_cast<unsigned char*>(mmap(nullptr, new_size,
PROT_WRITE | PROT_READ,
MAP_ANON | MAP_PRIVATE, -1, 0));
if (*typetable == MAP_FAILED) return -1;
bcopy(old_table, *typetable, *tablesize);
} else {
- unsigned char* new_table = static_cast<unsigned char*>(mmap(NULL, new_size,
+ unsigned char* new_table = static_cast<unsigned char*>(mmap(nullptr, new_size,
PROT_WRITE | PROT_READ,
MAP_ANON | MAP_PRIVATE, -1, 0));
if (new_table == MAP_FAILED) return -1;
@@ -695,8 +695,8 @@
if (prec < 0) {
memset(&mbs, 0, sizeof(mbs));
p = wcsarg;
- nbytes = wcsrtombs(NULL, (const wchar_t**)&p, 0, &mbs);
- if (nbytes == (size_t)-1) return NULL;
+ nbytes = wcsrtombs(nullptr, (const wchar_t**)&p, 0, &mbs);
+ if (nbytes == (size_t)-1) return nullptr;
} else {
// Optimisation: if the output precision is small enough,
// just allocate enough memory for the maximum instead of
@@ -712,17 +712,17 @@
if (clen == 0 || clen == (size_t)-1 || nbytes + clen > (size_t)prec) break;
nbytes += clen;
}
- if (clen == (size_t)-1) return NULL;
+ if (clen == (size_t)-1) return nullptr;
}
}
- if ((convbuf = static_cast<char*>(malloc(nbytes + 1))) == NULL) return NULL;
+ if ((convbuf = static_cast<char*>(malloc(nbytes + 1))) == nullptr) return nullptr;
// Fill the output buffer.
p = wcsarg;
memset(&mbs, 0, sizeof(mbs));
if ((nbytes = wcsrtombs(convbuf, (const wchar_t**)&p, nbytes, &mbs)) == (size_t)-1) {
free(convbuf);
- return NULL;
+ return nullptr;
}
convbuf[nbytes] = '\0';
return convbuf;
@@ -764,7 +764,7 @@
const char* p;
size_t insize, nchars, nconv;
- if (mbsarg == NULL) return NULL;
+ if (mbsarg == nullptr) return nullptr;
// Supplied argument is a multibyte string; convert it to wide characters first.
if (prec >= 0) {
@@ -779,7 +779,7 @@
nchars++;
insize += nconv;
}
- if (nconv == (size_t)-1 || nconv == (size_t)-2) return (NULL);
+ if (nconv == (size_t)-1 || nconv == (size_t)-2) return (nullptr);
} else {
insize = strlen(mbsarg);
}
@@ -788,7 +788,7 @@
// converting at most `size' bytes of the input multibyte string to
// wide characters for printing.
wchar_t* convbuf = static_cast<wchar_t*>(calloc(insize + 1, sizeof(*convbuf)));
- if (convbuf == NULL) return NULL;
+ if (convbuf == nullptr) return nullptr;
wchar_t* wcp = convbuf;
p = mbsarg;
bzero(&mbs, sizeof(mbs));
@@ -802,7 +802,7 @@
}
if (nconv == (size_t)-1 || nconv == (size_t)-2) {
free(convbuf);
- return NULL;
+ return nullptr;
}
*wcp = '\0';
diff --git a/libc/stdio/stdio_ext.cpp b/libc/stdio/stdio_ext.cpp
index e17b62a..945813e 100644
--- a/libc/stdio/stdio_ext.cpp
+++ b/libc/stdio/stdio_ext.cpp
@@ -69,7 +69,7 @@
void _flushlbf() {
// If we flush all streams, we know we've flushed all the line-buffered streams.
- fflush(NULL);
+ fflush(nullptr);
}
void __fseterr(FILE* fp) {
diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.cpp
index 17e4372..7a67868 100644
--- a/libc/stdio/vfprintf.cpp
+++ b/libc/stdio/vfprintf.cpp
@@ -64,7 +64,7 @@
* D: expchar holds this character; '\0' if no exponent, e.g. %f
* F: at least two digits for decimal, at least one digit for hex
*/
- char* decimal_point = NULL;
+ char* decimal_point = nullptr;
int signflag; /* true if float is negative */
union { /* floating point arguments %[aAeEfFgG] */
double dbl;
@@ -77,7 +77,7 @@
int lead; /* sig figs before decimal or group sep */
int ndig; /* actual number of digits returned by dtoa */
CHAR_TYPE expstr[MAXEXPDIG + 2]; /* buffer for exponent string: e+ZZZ */
- char* dtoaresult = NULL;
+ char* dtoaresult = nullptr;
uintmax_t _umax; /* integer arguments %[diouxX] */
enum { OCT, DEC, HEX } base; /* base for %[diouxX] conversion */
@@ -146,14 +146,14 @@
}
CHAR_TYPE* fmt = const_cast<CHAR_TYPE*>(fmt0);
- argtable = NULL;
+ argtable = nullptr;
nextarg = 1;
va_copy(orgap, ap);
uio.uio_iov = iovp = iov;
uio.uio_resid = 0;
uio.uio_iovcnt = 0;
ret = 0;
- convbuf = NULL;
+ convbuf = nullptr;
/*
* Scan the format for conversions (`%' character).
@@ -226,7 +226,7 @@
}
if (ch == '$') {
nextarg = n;
- if (argtable == NULL) {
+ if (argtable == nullptr) {
argtable = statargtable;
if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
ret = -1;
@@ -261,7 +261,7 @@
} while (is_digit(ch));
if (ch == '$') {
nextarg = n;
- if (argtable == NULL) {
+ if (argtable == nullptr) {
argtable = statargtable;
if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
ret = -1;
@@ -353,14 +353,14 @@
if (flags & LONGDBL) {
fparg.ldbl = GETARG(long double);
dtoaresult = cp = __hldtoa(fparg.ldbl, xdigs, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
} else {
fparg.dbl = GETARG(double);
dtoaresult = cp = __hdtoa(fparg.dbl, xdigs, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
@@ -390,14 +390,14 @@
if (flags & LONGDBL) {
fparg.ldbl = GETARG(long double);
dtoaresult = cp = __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
} else {
fparg.dbl = GETARG(double);
dtoaresult = cp = __dtoa(fparg.dbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
@@ -479,18 +479,18 @@
wchar_t* wcp;
free(convbuf);
- convbuf = NULL;
- if ((wcp = GETARG(wchar_t*)) == NULL) {
+ convbuf = nullptr;
+ if ((wcp = GETARG(wchar_t*)) == nullptr) {
cp = const_cast<char*>("(null)");
} else {
convbuf = helpers::wcsconv(wcp, prec);
- if (convbuf == NULL) {
+ if (convbuf == nullptr) {
ret = -1;
goto error;
}
cp = convbuf;
}
- } else if ((cp = GETARG(char*)) == NULL) {
+ } else if ((cp = GETARG(char*)) == nullptr) {
cp = const_cast<char*>("(null)");
}
if (prec >= 0) {
@@ -625,7 +625,7 @@
if ((flags & FPT) == 0) {
PRINT(cp, size);
} else { /* glue together f_p fragments */
- if (decimal_point == NULL) decimal_point = nl_langinfo(RADIXCHAR);
+ if (decimal_point == nullptr) decimal_point = nl_langinfo(RADIXCHAR);
if (!expchar) { /* %[fF] or sufficiently short %[gG] */
if (expt <= 0) {
PRINT(zeroes, 1);
@@ -676,9 +676,9 @@
finish:
free(convbuf);
if (dtoaresult) __freedtoa(dtoaresult);
- if (argtable != NULL && argtable != statargtable) {
+ if (argtable != nullptr && argtable != statargtable) {
munmap(argtable, argtablesiz);
- argtable = NULL;
+ argtable = nullptr;
}
return (ret);
}
diff --git a/libc/stdio/vfscanf.cpp b/libc/stdio/vfscanf.cpp
index 49d6bf6..0fcdbed 100644
--- a/libc/stdio/vfscanf.cpp
+++ b/libc/stdio/vfscanf.cpp
@@ -97,7 +97,7 @@
char buf[BUF]; /* buffer for numeric conversions */
size_t nconv; /* length of multibyte sequence converted */
mbstate_t mbs;
- void* allocation = NULL; // Allocated but unassigned result for %mc/%ms/%m[.
+ void* allocation = nullptr; // Allocated but unassigned result for %mc/%ms/%m[.
size_t capacity = 0; // Number of char/wchar_t units allocated in `allocation`.
/* `basefix' is used to avoid `if' tests in the integer scanner */
@@ -334,9 +334,9 @@
if (flags & LONG) {
if (flags & ALLOCATE) {
allocation = wcp = reinterpret_cast<wchar_t*>(malloc(width * sizeof(wchar_t)));
- if (allocation == NULL) goto allocation_failure;
+ if (allocation == nullptr) goto allocation_failure;
} else if (flags & SUPPRESS) {
- wcp = NULL;
+ wcp = nullptr;
} else {
wcp = va_arg(ap, wchar_t*);
}
@@ -370,9 +370,9 @@
break;
}
}
- if (allocation != NULL) {
+ if (allocation != nullptr) {
*va_arg(ap, wchar_t**) = reinterpret_cast<wchar_t*>(allocation);
- allocation = NULL;
+ allocation = nullptr;
}
if (!(flags & SUPPRESS)) nassigned++;
} else if (flags & SUPPRESS) {
@@ -397,15 +397,15 @@
} else {
if (flags & ALLOCATE) {
allocation = p = reinterpret_cast<char*>(malloc(width));
- if (allocation == NULL) goto allocation_failure;
+ if (allocation == nullptr) goto allocation_failure;
} else {
p = va_arg(ap, char*);
}
size_t r = fread(p, 1, width, fp);
if (r == 0) goto input_failure;
- if (allocation != NULL) {
+ if (allocation != nullptr) {
*va_arg(ap, char**) = reinterpret_cast<char*>(allocation);
- allocation = NULL;
+ allocation = nullptr;
}
nread += r;
nassigned++;
@@ -423,9 +423,9 @@
if (flags & ALLOCATE) {
capacity = MIN(width, 32);
allocation = wcp = reinterpret_cast<wchar_t*>(malloc(sizeof(wchar_t) * capacity));
- if (allocation == NULL) goto allocation_failure;
+ if (allocation == nullptr) goto allocation_failure;
} else if (flags & SUPPRESS) {
- wcp = NULL;
+ wcp = nullptr;
} else {
wcp = va_arg(ap, wchar_t*);
}
@@ -455,11 +455,11 @@
}
if (wcp) wcp[n] = wc;
n++;
- if (allocation != NULL && n == capacity) {
+ if (allocation != nullptr && n == capacity) {
capacity *= 2;
wchar_t* new_allocation =
reinterpret_cast<wchar_t*>(realloc(allocation, sizeof(wchar_t) * capacity));
- if (new_allocation == NULL) goto allocation_failure;
+ if (new_allocation == nullptr) goto allocation_failure;
allocation = wcp = new_allocation;
}
nread += bytes;
@@ -478,9 +478,9 @@
fp->_flags |= __SERR;
goto input_failure;
}
- if (allocation != NULL) {
+ if (allocation != nullptr) {
*va_arg(ap, wchar_t**) = reinterpret_cast<wchar_t*>(allocation);
- allocation = NULL;
+ allocation = nullptr;
}
} else if (flags & SUPPRESS) {
n = 0;
@@ -497,7 +497,7 @@
if (flags & ALLOCATE) {
capacity = MIN(width, 32);
allocation = p = reinterpret_cast<char*>(malloc(capacity));
- if (allocation == NULL) goto allocation_failure;
+ if (allocation == nullptr) goto allocation_failure;
} else {
p = va_arg(ap, char*);
}
@@ -505,10 +505,10 @@
while (ccltab[*fp->_p]) {
fp->_r--;
p[n++] = *fp->_p++;
- if (allocation != NULL && n == capacity) {
+ if (allocation != nullptr && n == capacity) {
capacity *= 2;
char* new_allocation = reinterpret_cast<char*>(realloc(allocation, capacity));
- if (new_allocation == NULL) goto allocation_failure;
+ if (new_allocation == nullptr) goto allocation_failure;
allocation = p = new_allocation;
}
if (--width == 0) break;
@@ -518,9 +518,9 @@
}
}
nread += n;
- if (allocation != NULL) {
+ if (allocation != nullptr) {
*va_arg(ap, char**) = reinterpret_cast<char*>(allocation);
- allocation = NULL;
+ allocation = nullptr;
}
}
if (c == CT_CCL && n == 0) goto match_failure;
@@ -671,9 +671,9 @@
*p = '\0';
if (flags & UNSIGNED) {
- res = strtoumax(buf, NULL, base);
+ res = strtoumax(buf, nullptr, base);
} else {
- res = strtoimax(buf, NULL, base);
+ res = strtoimax(buf, nullptr, base);
}
if (flags & POINTER) {
*va_arg(ap, void**) = (void*)(uintptr_t)res;
diff --git a/libc/stdio/vfwprintf.cpp b/libc/stdio/vfwprintf.cpp
index 46b6233..ae0b62f 100644
--- a/libc/stdio/vfwprintf.cpp
+++ b/libc/stdio/vfwprintf.cpp
@@ -64,7 +64,7 @@
* D: expchar holds this character; '\0' if no exponent, e.g. %f
* F: at least two digits for decimal, at least one digit for hex
*/
- char* decimal_point = NULL;
+ char* decimal_point = nullptr;
int signflag; /* true if float is negative */
union { /* floating point arguments %[aAeEfFgG] */
double dbl;
@@ -77,7 +77,7 @@
int lead; /* sig figs before decimal or group sep */
int ndig; /* actual number of digits returned by dtoa */
CHAR_TYPE expstr[MAXEXPDIG + 2]; /* buffer for exponent string: e+ZZZ */
- char* dtoaresult = NULL;
+ char* dtoaresult = nullptr;
uintmax_t _umax; /* integer arguments %[diouxX] */
enum { OCT, DEC, HEX } base; /* base for %[diouxX] conversion */
@@ -135,14 +135,14 @@
}
CHAR_TYPE* fmt = const_cast<CHAR_TYPE*>(fmt0);
- argtable = NULL;
+ argtable = nullptr;
nextarg = 1;
va_copy(orgap, ap);
uio.uio_iov = iovp = iov;
uio.uio_resid = 0;
uio.uio_iovcnt = 0;
ret = 0;
- convbuf = NULL;
+ convbuf = nullptr;
/*
* Scan the format for conversions (`%' character).
@@ -215,7 +215,7 @@
}
if (ch == '$') {
nextarg = n;
- if (argtable == NULL) {
+ if (argtable == nullptr) {
argtable = statargtable;
if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
ret = -1;
@@ -250,7 +250,7 @@
} while (is_digit(ch));
if (ch == '$') {
nextarg = n;
- if (argtable == NULL) {
+ if (argtable == nullptr) {
argtable = statargtable;
if (__find_arguments(fmt0, orgap, &argtable, &argtablesiz) == -1) {
ret = -1;
@@ -331,14 +331,14 @@
if (flags & LONGDBL) {
fparg.ldbl = GETARG(long double);
dtoaresult = __hldtoa(fparg.ldbl, xdigs, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
} else {
fparg.dbl = GETARG(double);
dtoaresult = __hdtoa(fparg.dbl, xdigs, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
@@ -347,7 +347,7 @@
if (expt == INT_MAX) ox[1] = '\0';
free(convbuf);
cp = convbuf = helpers::mbsconv(dtoaresult, -1);
- if (cp == NULL) goto error;
+ if (cp == nullptr) goto error;
ndig = dtoaend - dtoaresult;
goto fp_common;
case 'e':
@@ -372,14 +372,14 @@
if (flags & LONGDBL) {
fparg.ldbl = GETARG(long double);
dtoaresult = __ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
} else {
fparg.dbl = GETARG(double);
dtoaresult = __dtoa(fparg.dbl, expchar ? 2 : 3, prec, &expt, &signflag, &dtoaend);
- if (dtoaresult == NULL) {
+ if (dtoaresult == nullptr) {
errno = ENOMEM;
goto error;
}
@@ -387,7 +387,7 @@
}
free(convbuf);
cp = convbuf = helpers::mbsconv(dtoaresult, -1);
- if (cp == NULL) goto error;
+ if (cp == nullptr) goto error;
ndig = dtoaend - dtoaresult;
fp_common:
if (signflag) sign = '-';
@@ -461,13 +461,13 @@
/*FALLTHROUGH*/
case 's':
if (flags & LONGINT) {
- if ((cp = GETARG(wchar_t*)) == NULL) cp = const_cast<wchar_t*>(L"(null)");
+ if ((cp = GETARG(wchar_t*)) == nullptr) cp = const_cast<wchar_t*>(L"(null)");
} else {
char* mbsarg;
- if ((mbsarg = GETARG(char*)) == NULL) mbsarg = const_cast<char*>("(null)");
+ if ((mbsarg = GETARG(char*)) == nullptr) mbsarg = const_cast<char*>("(null)");
free(convbuf);
convbuf = helpers::mbsconv(mbsarg, prec);
- if (convbuf == NULL) {
+ if (convbuf == nullptr) {
fp->_flags |= __SERR;
goto error;
} else {
@@ -606,7 +606,7 @@
if ((flags & FPT) == 0) {
PRINT(cp, size);
} else { /* glue together f_p fragments */
- if (decimal_point == NULL) decimal_point = nl_langinfo(RADIXCHAR);
+ if (decimal_point == nullptr) decimal_point = nl_langinfo(RADIXCHAR);
if (!expchar) { /* %[fF] or sufficiently short %[gG] */
if (expt <= 0) {
PRINT(zeroes, 1);
@@ -654,9 +654,9 @@
finish:
free(convbuf);
if (dtoaresult) __freedtoa(dtoaresult);
- if (argtable != NULL && argtable != statargtable) {
+ if (argtable != nullptr && argtable != statargtable) {
munmap(argtable, argtablesiz);
- argtable = NULL;
+ argtable = nullptr;
}
return (ret);
}