Skip to content

Commit 154f9a8

Browse files
authored
Replace 0 with nullptr where appropriate (#1250)
1 parent 2521e64 commit 154f9a8

File tree

10 files changed

+27
-26
lines changed

10 files changed

+27
-26
lines changed

stl/src/cthread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ _CRTIMP2_PURE void _Thrd_exit(int res) { // terminate execution of calling threa
4848

4949
// TRANSITION, ABI: _Thrd_start() is preserved for binary compatibility
5050
_CRTIMP2_PURE int _Thrd_start(_Thrd_t* thr, _Thrd_callback_t func, void* b) { // start a thread
51-
thr->_Hnd = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, func, b, 0, &thr->_Id));
52-
return thr->_Hnd == 0 ? _Thrd_error : _Thrd_success;
51+
thr->_Hnd = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, func, b, 0, &thr->_Id));
52+
return thr->_Hnd == nullptr ? _Thrd_error : _Thrd_success;
5353
}
5454

5555
int _Thrd_join(_Thrd_t thr, int* code) { // return exit code when thread terminates

stl/src/filesys.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static HANDLE _FilesysOpenFile(const wchar_t* _Fname, DWORD _Desired_access, DWO
5252
return CreateFile2(_Fname, _Desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, OPEN_EXISTING,
5353
&_Create_file_parameters);
5454
#else // _CRT_APP
55-
return CreateFileW(
56-
_Fname, _Desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, _Flags, 0);
55+
return CreateFileW(_Fname, _Desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
56+
OPEN_EXISTING, _Flags, nullptr);
5757
#endif // _CRT_APP
5858
}
5959

@@ -174,7 +174,7 @@ _FS_DLL wchar_t* __CLRCALL_PURE_OR_CDECL _Temp_get(wchar_t (&_Dest)[_MAX_FILESYS
174174

175175
_FS_DLL int __CLRCALL_PURE_OR_CDECL _Make_dir(const wchar_t* _Fname, const wchar_t*) {
176176
// make a new directory (ignore attributes)
177-
int _Ans = CreateDirectoryW(_Fname, 0);
177+
int _Ans = CreateDirectoryW(_Fname, nullptr);
178178

179179
if (_Ans != 0) {
180180
return 1;
@@ -195,7 +195,7 @@ _FS_DLL file_type __CLRCALL_PURE_OR_CDECL _Stat(const wchar_t* _Fname, perms* _P
195195

196196
if (GetFileAttributesExW(_Fname, GetFileExInfoStandard, &_Data)) {
197197
// get file type and return permissions
198-
if (_Pmode != 0) {
198+
if (_Pmode != nullptr) {
199199
constexpr perms _Write_perms = perms::owner_write | perms::group_write | perms::others_write;
200200
constexpr perms _Readonly_perms = perms::all & ~_Write_perms;
201201

@@ -398,7 +398,7 @@ _FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t* _Fname1, const wchar_t*
398398
(void) _Fname2;
399399
return errno = EDOM; // hardlinks not supported
400400
#else // _CRT_APP
401-
return CreateHardLinkW(_Fname2, _Fname1, 0) != 0 ? 0 : GetLastError();
401+
return CreateHardLinkW(_Fname2, _Fname1, nullptr) != 0 ? 0 : GetLastError();
402402
#endif // _CRT_APP
403403
}
404404

@@ -426,7 +426,7 @@ _FS_DLL int __CLRCALL_PURE_OR_CDECL _Resize(const wchar_t* _Fname, uintmax_t _Ne
426426
if (_Handle != INVALID_HANDLE_VALUE) { // set file pointer to new size and trim
427427
LARGE_INTEGER _Large;
428428
_Large.QuadPart = _Newsize;
429-
_Ok = SetFilePointerEx(_Handle, _Large, 0, FILE_BEGIN) != 0 && SetEndOfFile(_Handle) != 0;
429+
_Ok = SetFilePointerEx(_Handle, _Large, nullptr, FILE_BEGIN) != 0 && SetEndOfFile(_Handle) != 0;
430430
CloseHandle(_Handle);
431431
}
432432
return _Ok ? 0 : GetLastError();

stl/src/filesystem.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ _EXTERN_C
271271
_In_ const __std_fs_file_flags _Flags) noexcept { // calls CreateFile2 or CreateFileW
272272
const HANDLE _Result = __vcp_CreateFile(_File_name, static_cast<unsigned long>(_Desired_access),
273273
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING,
274-
static_cast<unsigned long>(_Flags), 0);
274+
static_cast<unsigned long>(_Flags), nullptr);
275275
*_Handle = static_cast<__std_fs_file_handle>(reinterpret_cast<intptr_t>(_Result));
276276
return _Translate_CreateFile_last_error(_Result);
277277
}
@@ -462,15 +462,15 @@ void __stdcall __std_fs_directory_iterator_close(_In_ const __std_fs_dir_handle
462462
// We test equivalent() not by directly doing what equivalent() does, but by opening the handles
463463
// in exclusive mode, so a subsequent open will fail with ERROR_SHARING_VIOLATION.
464464
{
465-
const _STD _Fs_file _Source_handle(
466-
__vcp_CreateFile(_Source, FILE_READ_ATTRIBUTES | FILE_READ_DATA, 0, nullptr, OPEN_EXISTING, 0, 0));
465+
const _STD _Fs_file _Source_handle(__vcp_CreateFile(
466+
_Source, FILE_READ_ATTRIBUTES | FILE_READ_DATA, 0, nullptr, OPEN_EXISTING, 0, nullptr));
467467
__std_win_error _Last_error = _Translate_CreateFile_last_error(_Source_handle._Get());
468468
if (_Last_error != __std_win_error::_Success) {
469469
return {false, _Last_error};
470470
}
471471

472-
const _STD _Fs_file _Target_handle(
473-
__vcp_CreateFile(_Target, FILE_READ_ATTRIBUTES | FILE_WRITE_DATA, 0, nullptr, OPEN_EXISTING, 0, 0));
472+
const _STD _Fs_file _Target_handle(__vcp_CreateFile(
473+
_Target, FILE_READ_ATTRIBUTES | FILE_WRITE_DATA, 0, nullptr, OPEN_EXISTING, 0, nullptr));
474474
_Last_error = _Translate_CreateFile_last_error(_Target_handle._Get());
475475
if (_Last_error != __std_win_error::_Success) {
476476
// Also handles the equivalent(from, to) error case
@@ -767,7 +767,7 @@ _Success_(return == __std_win_error::_Success) __std_win_error
767767

768768
LARGE_INTEGER _Large;
769769
_Large.QuadPart = _New_size;
770-
if (SetFilePointerEx(_Handle._Get(), _Large, 0, FILE_BEGIN) == 0 || SetEndOfFile(_Handle._Get()) == 0) {
770+
if (SetFilePointerEx(_Handle._Get(), _Large, nullptr, FILE_BEGIN) == 0 || SetEndOfFile(_Handle._Get()) == 0) {
771771
return __std_win_error{GetLastError()};
772772
}
773773

stl/src/fiopen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ _STD_BEGIN
1111

1212
FILE* _Xfsopen(_In_z_ const char* filename, _In_ int mode, _In_ int prot) {
1313
static const char* const mods[] = {// fopen mode strings corresponding to valid[i]
14-
"r", "w", "w", "a", "rb", "wb", "wb", "ab", "r+", "w+", "a+", "r+b", "w+b", "a+b", 0};
14+
"r", "w", "w", "a", "rb", "wb", "wb", "ab", "r+", "w+", "a+", "r+b", "w+b", "a+b", nullptr};
1515

1616
return _fsopen(filename, mods[mode], prot);
1717
}
1818

1919
FILE* _Xfsopen(_In_z_ const wchar_t* filename, _In_ int mode, _In_ int prot) {
2020
static const wchar_t* const mods[] = {// fopen mode strings corresponding to valid[i]
21-
L"r", L"w", L"w", L"a", L"rb", L"wb", L"wb", L"ab", L"r+", L"w+", L"a+", L"r+b", L"w+b", L"a+b", 0};
21+
L"r", L"w", L"w", L"a", L"rb", L"wb", L"wb", L"ab", L"r+", L"w+", L"a+", L"r+b", L"w+b", L"a+b", nullptr};
2222

2323
return _wfsopen(filename, mods[mode], prot);
2424
}

stl/src/ios.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ __PURE_APPDOMAIN_GLOBAL int ios_base::_Index = 0; // initialize source of unique
2222
__PURE_APPDOMAIN_GLOBAL bool ios_base::_Sync = true; // initialize synchronization flag
2323

2424

25-
__PURE_APPDOMAIN_GLOBAL static ios_base* stdstr[_Nstdstr + 2] = {0}; // [1, _Nstdstr] hold pointers to standard streams
25+
__PURE_APPDOMAIN_GLOBAL static ios_base* stdstr[_Nstdstr + 2] = {
26+
nullptr}; // [1, _Nstdstr] hold pointers to standard streams
2627
__PURE_APPDOMAIN_GLOBAL static char stdopens[_Nstdstr + 2] = {0}; // [1, _Nstdstr] hold open counts for standard streams
2728

2829
// void __CLR_OR_THIS_CALL ios_base::clear(iostate state, bool reraise) { // set state, possibly reraise exception

stl/src/taskscheduler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ namespace Concurrency {
4848
// that as a failure to call.
4949
(void) _Flags;
5050
(void) _Addr;
51-
return 0;
51+
return nullptr;
5252
#else // ^^^ defined(_CRT_APP) ^^^ // vvv !defined(_CRT_APP) vvv
5353
HMODULE _Result;
5454
if (::GetModuleHandleExW(_Flags, _Addr, &_Result) == 0) {
55-
return 0;
55+
return nullptr;
5656
}
5757

5858
return _Result;
@@ -66,7 +66,7 @@ namespace Concurrency {
6666
return _STL_host_status::_Dll;
6767
#else // ^^^ CRTDLL2 ^^^ // vvv !CRTDLL2 vvv
6868
HANDLE _HExe = _Call_get_module_handle_ex(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, nullptr);
69-
if (_HExe == 0) {
69+
if (_HExe == nullptr) {
7070
return _STL_host_status::_Unknown;
7171
} else if (_HExe == reinterpret_cast<HMODULE>(&__ImageBase)) {
7272
return _STL_host_status::_Exe;
@@ -133,7 +133,7 @@ namespace Concurrency {
133133
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
134134
reinterpret_cast<LPCWSTR>(_Chore->_M_callback));
135135

136-
if (_Callback_dll != 0) {
136+
if (_Callback_dll != nullptr) {
137137
__crtFreeLibraryWhenCallbackReturns(_Pci, _Callback_dll);
138138
}
139139
}

stl/src/winapisupp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ extern "C" void __cdecl __crtGetSystemTimePreciseAsFileTime(_Out_ LPFILETIME lpS
530530

531531
#else // defined _ONECORE
532532

533-
extern "C" PVOID __KERNEL32Functions[eMaxKernel32Function] = {0};
533+
extern "C" PVOID __KERNEL32Functions[eMaxKernel32Function] = {nullptr};
534534

535535
static int __cdecl initialize_pointers() {
536536
HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");

stl/src/xstoul.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ _CRTIMP2_PURE unsigned long __CLRCALL_PURE_OR_CDECL _Stoulx(
7474
}
7575

7676
x = 0;
77-
for (s2 = sc, y = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != 0;
77+
for (s2 = sc, y = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != nullptr;
7878
++sc) { // accumulate digits
7979
y = x;
8080
dig = static_cast<char>(sd - digits); // for overflow checking

stl/src/xstoull.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ _CRTIMP2_PURE unsigned long long __CLRCALL_PURE_OR_CDECL _Stoullx(
7070
}
7171

7272
x = 0;
73-
for (s2 = sc, y = 0, dig = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != 0;
73+
for (s2 = sc, y = 0, dig = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != nullptr;
7474
++sc) { // accumulate digits
7575
y = x;
7676
dig = static_cast<char>(sd - digits); // for overflow checking

stl/src/xstoxflt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ _In_range_(0, maxsig) int _Stoxflt(
4242
seen = 1;
4343
}
4444

45-
while ((pd = static_cast<const char*>(memchr(&digits[0], *s, 22))) != 0) {
45+
while ((pd = static_cast<const char*>(memchr(&digits[0], *s, 22))) != nullptr) {
4646
if (nsig <= maxsig) {
4747
buf[nsig++] = vals[pd - digits]; // accumulate a digit
4848
} else {
@@ -63,7 +63,7 @@ _In_range_(0, maxsig) int _Stoxflt(
6363
}
6464
}
6565

66-
for (; (pd = static_cast<const char*>(memchr(&digits[0], *s, 22))) != 0; ++s, seen = 1) {
66+
for (; (pd = static_cast<const char*>(memchr(&digits[0], *s, 22))) != nullptr; ++s, seen = 1) {
6767
if (nsig <= maxsig) { // accumulate a fraction digit
6868
buf[nsig++] = vals[pd - digits];
6969
--lo[0];

0 commit comments

Comments
 (0)