Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stl/src/cthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ _CRTIMP2_PURE void _Thrd_exit(int res) { // terminate execution of calling threa

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

int _Thrd_join(_Thrd_t thr, int* code) { // return exit code when thread terminates
Expand Down
12 changes: 6 additions & 6 deletions stl/src/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static HANDLE _FilesysOpenFile(const wchar_t* _Fname, DWORD _Desired_access, DWO
return CreateFile2(_Fname, _Desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, OPEN_EXISTING,
&_Create_file_parameters);
#else // _CRT_APP
return CreateFileW(
_Fname, _Desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, _Flags, 0);
return CreateFileW(_Fname, _Desired_access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, _Flags, nullptr);
#endif // _CRT_APP
}

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

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

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

if (GetFileAttributesExW(_Fname, GetFileExInfoStandard, &_Data)) {
// get file type and return permissions
if (_Pmode != 0) {
if (_Pmode != nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use conversion to bool here, aka if (_Pmode)?

Would apply throughout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our codebase is currently inconsistent about testing pointers directly (or negated), versus comparing them to nullptr. (Unlike integers, where we strongly prefer to explicitly compare them against zero.) I personally like directly testing pointers, because I believe it reads naturally ("if we have pointer, do cool things with it") and avoids the double negation inherent in "not null". However, I think that if we want to consistently test pointers directly, we should do so as a separate cleanup change.

constexpr perms _Write_perms = perms::owner_write | perms::group_write | perms::others_write;
constexpr perms _Readonly_perms = perms::all & ~_Write_perms;

Expand Down Expand Up @@ -398,7 +398,7 @@ _FS_DLL int __CLRCALL_PURE_OR_CDECL _Link(const wchar_t* _Fname1, const wchar_t*
(void) _Fname2;
return errno = EDOM; // hardlinks not supported
#else // _CRT_APP
return CreateHardLinkW(_Fname2, _Fname1, 0) != 0 ? 0 : GetLastError();
return CreateHardLinkW(_Fname2, _Fname1, nullptr) != 0 ? 0 : GetLastError();
#endif // _CRT_APP
}

Expand Down Expand Up @@ -426,7 +426,7 @@ _FS_DLL int __CLRCALL_PURE_OR_CDECL _Resize(const wchar_t* _Fname, uintmax_t _Ne
if (_Handle != INVALID_HANDLE_VALUE) { // set file pointer to new size and trim
LARGE_INTEGER _Large;
_Large.QuadPart = _Newsize;
_Ok = SetFilePointerEx(_Handle, _Large, 0, FILE_BEGIN) != 0 && SetEndOfFile(_Handle) != 0;
_Ok = SetFilePointerEx(_Handle, _Large, nullptr, FILE_BEGIN) != 0 && SetEndOfFile(_Handle) != 0;
CloseHandle(_Handle);
}
return _Ok ? 0 : GetLastError();
Expand Down
12 changes: 6 additions & 6 deletions stl/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ _EXTERN_C
_In_ const __std_fs_file_flags _Flags) noexcept { // calls CreateFile2 or CreateFileW
const HANDLE _Result = __vcp_CreateFile(_File_name, static_cast<unsigned long>(_Desired_access),
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING,
static_cast<unsigned long>(_Flags), 0);
static_cast<unsigned long>(_Flags), nullptr);
*_Handle = static_cast<__std_fs_file_handle>(reinterpret_cast<intptr_t>(_Result));
return _Translate_CreateFile_last_error(_Result);
}
Expand Down Expand Up @@ -462,15 +462,15 @@ void __stdcall __std_fs_directory_iterator_close(_In_ const __std_fs_dir_handle
// We test equivalent() not by directly doing what equivalent() does, but by opening the handles
// in exclusive mode, so a subsequent open will fail with ERROR_SHARING_VIOLATION.
{
const _STD _Fs_file _Source_handle(
__vcp_CreateFile(_Source, FILE_READ_ATTRIBUTES | FILE_READ_DATA, 0, nullptr, OPEN_EXISTING, 0, 0));
const _STD _Fs_file _Source_handle(__vcp_CreateFile(
_Source, FILE_READ_ATTRIBUTES | FILE_READ_DATA, 0, nullptr, OPEN_EXISTING, 0, nullptr));
__std_win_error _Last_error = _Translate_CreateFile_last_error(_Source_handle._Get());
if (_Last_error != __std_win_error::_Success) {
return {false, _Last_error};
}

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

LARGE_INTEGER _Large;
_Large.QuadPart = _New_size;
if (SetFilePointerEx(_Handle._Get(), _Large, 0, FILE_BEGIN) == 0 || SetEndOfFile(_Handle._Get()) == 0) {
if (SetFilePointerEx(_Handle._Get(), _Large, nullptr, FILE_BEGIN) == 0 || SetEndOfFile(_Handle._Get()) == 0) {
return __std_win_error{GetLastError()};
}

Expand Down
4 changes: 2 additions & 2 deletions stl/src/fiopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ _STD_BEGIN

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

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

FILE* _Xfsopen(_In_z_ const wchar_t* filename, _In_ int mode, _In_ int prot) {
static const wchar_t* const mods[] = {// fopen mode strings corresponding to valid[i]
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};
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};

return _wfsopen(filename, mods[mode], prot);
}
Expand Down
3 changes: 2 additions & 1 deletion stl/src/ios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ __PURE_APPDOMAIN_GLOBAL int ios_base::_Index = 0; // initialize source of unique
__PURE_APPDOMAIN_GLOBAL bool ios_base::_Sync = true; // initialize synchronization flag


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

// void __CLR_OR_THIS_CALL ios_base::clear(iostate state, bool reraise) { // set state, possibly reraise exception
Expand Down
8 changes: 4 additions & 4 deletions stl/src/taskscheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ namespace Concurrency {
// that as a failure to call.
(void) _Flags;
(void) _Addr;
return 0;
return nullptr;
#else // ^^^ defined(_CRT_APP) ^^^ // vvv !defined(_CRT_APP) vvv
HMODULE _Result;
if (::GetModuleHandleExW(_Flags, _Addr, &_Result) == 0) {
return 0;
return nullptr;
}

return _Result;
Expand All @@ -66,7 +66,7 @@ namespace Concurrency {
return _STL_host_status::_Dll;
#else // ^^^ CRTDLL2 ^^^ // vvv !CRTDLL2 vvv
HANDLE _HExe = _Call_get_module_handle_ex(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, nullptr);
if (_HExe == 0) {
if (_HExe == nullptr) {
return _STL_host_status::_Unknown;
} else if (_HExe == reinterpret_cast<HMODULE>(&__ImageBase)) {
return _STL_host_status::_Exe;
Expand Down Expand Up @@ -133,7 +133,7 @@ namespace Concurrency {
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
reinterpret_cast<LPCWSTR>(_Chore->_M_callback));

if (_Callback_dll != 0) {
if (_Callback_dll != nullptr) {
__crtFreeLibraryWhenCallbackReturns(_Pci, _Callback_dll);
}
}
Expand Down
2 changes: 1 addition & 1 deletion stl/src/winapisupp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ extern "C" void __cdecl __crtGetSystemTimePreciseAsFileTime(_Out_ LPFILETIME lpS

#else // defined _ONECORE

extern "C" PVOID __KERNEL32Functions[eMaxKernel32Function] = {0};
extern "C" PVOID __KERNEL32Functions[eMaxKernel32Function] = {nullptr};

static int __cdecl initialize_pointers() {
HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");
Expand Down
2 changes: 1 addition & 1 deletion stl/src/xstoul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ _CRTIMP2_PURE unsigned long __CLRCALL_PURE_OR_CDECL _Stoulx(
}

x = 0;
for (s2 = sc, y = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != 0;
for (s2 = sc, y = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != nullptr;
++sc) { // accumulate digits
y = x;
dig = static_cast<char>(sd - digits); // for overflow checking
Expand Down
2 changes: 1 addition & 1 deletion stl/src/xstoull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _CRTIMP2_PURE unsigned long long __CLRCALL_PURE_OR_CDECL _Stoullx(
}

x = 0;
for (s2 = sc, y = 0, dig = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != 0;
for (s2 = sc, y = 0, dig = 0; (sd = static_cast<const char*>(memchr(&digits[0], tolower(*sc), base))) != nullptr;
++sc) { // accumulate digits
y = x;
dig = static_cast<char>(sd - digits); // for overflow checking
Expand Down
4 changes: 2 additions & 2 deletions stl/src/xstoxflt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _In_range_(0, maxsig) int _Stoxflt(
seen = 1;
}

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

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