Procházet zdrojové kódy

Clang-Tidy - modernize-use-nullptr.

Yao Wei Tjong 姚伟忠 před 8 roky
rodič
revize
c8bc642020

+ 1 - 1
Source/Samples/Utilities2D/Sample2D.cpp

@@ -538,7 +538,7 @@ void Sample2D::PlaySoundEffect(String soundName)
     auto* cache = GetSubsystem<ResourceCache>();
     auto* cache = GetSubsystem<ResourceCache>();
     auto* source = scene_->CreateComponent<SoundSource>();
     auto* source = scene_->CreateComponent<SoundSource>();
     auto* sound = cache->GetResource<Sound>("Sounds/" + soundName);
     auto* sound = cache->GetResource<Sound>("Sounds/" + soundName);
-    if (sound != NULL) {
+    if (sound != nullptr) {
         source->SetAutoRemoveMode(REMOVE_COMPONENT);
         source->SetAutoRemoveMode(REMOVE_COMPONENT);
         source->Play(sound);
         source->Play(sound);
     }
     }

+ 4 - 4
Source/Urho3D/Core/Condition.cpp

@@ -63,8 +63,8 @@ Condition::Condition() :
     mutex_(new pthread_mutex_t),
     mutex_(new pthread_mutex_t),
     event_(new pthread_cond_t)
     event_(new pthread_cond_t)
 {
 {
-    pthread_mutex_init((pthread_mutex_t*)mutex_, 0);
-    pthread_cond_init((pthread_cond_t*)event_, 0);
+    pthread_mutex_init((pthread_mutex_t*)mutex_, nullptr);
+    pthread_cond_init((pthread_cond_t*)event_, nullptr);
 }
 }
 
 
 Condition::~Condition()
 Condition::~Condition()
@@ -76,8 +76,8 @@ Condition::~Condition()
     pthread_mutex_destroy(mutex);
     pthread_mutex_destroy(mutex);
     delete cond;
     delete cond;
     delete mutex;
     delete mutex;
-    event_ = 0;
-    mutex_ = 0;
+    event_ = nullptr;
+    mutex_ = nullptr;
 }
 }
 
 
 void Condition::Set()
 void Condition::Set()

+ 1 - 1
Source/Urho3D/Core/Mutex.cpp

@@ -83,7 +83,7 @@ Mutex::~Mutex()
     auto* mutex = (pthread_mutex_t*)handle_;
     auto* mutex = (pthread_mutex_t*)handle_;
     pthread_mutex_destroy(mutex);
     pthread_mutex_destroy(mutex);
     delete mutex;
     delete mutex;
-    handle_ = 0;
+    handle_ = nullptr;
 }
 }
 
 
 void Mutex::Acquire()
 void Mutex::Acquire()

+ 71 - 71
Source/Urho3D/Core/ProcessUtils.cpp

@@ -46,18 +46,18 @@ extern "C" unsigned SDL_TVOS_GetActiveProcessorCount();
 #include <io.h>
 #include <io.h>
 #if defined(_MSC_VER)
 #if defined(_MSC_VER)
 #include <float.h>
 #include <float.h>
-#include <Lmcons.h> // For UNLEN. 
+#include <Lmcons.h> // For UNLEN.
 #elif defined(__MINGW32__)
 #elif defined(__MINGW32__)
-#include <lmcons.h> // For UNLEN. Apparently MSVC defines "<Lmcons.h>" (with an upperscore 'L' but MinGW uses an underscore 'l'). 
-#include <ntdef.h> 
+#include <lmcons.h> // For UNLEN. Apparently MSVC defines "<Lmcons.h>" (with an upperscore 'L' but MinGW uses an underscore 'l').
+#include <ntdef.h>
 #endif
 #endif
-#elif defined(__linux__) && !defined(__ANDROID__) 
-#include <pwd.h> 
+#elif defined(__linux__) && !defined(__ANDROID__)
+#include <pwd.h>
 #include <sys/sysinfo.h>
 #include <sys/sysinfo.h>
 #include <sys/utsname.h>
 #include <sys/utsname.h>
 #elif defined(__APPLE__)
 #elif defined(__APPLE__)
 #include <sys/sysctl.h>
 #include <sys/sysctl.h>
-#include <SystemConfiguration/SystemConfiguration.h> // For the detection functions inside GetLoginName(). 
+#include <SystemConfiguration/SystemConfiguration.h> // For the detection functions inside GetLoginName().
 #endif
 #endif
 #ifndef _WIN32
 #ifndef _WIN32
 #include <unistd.h>
 #include <unistd.h>
@@ -518,16 +518,16 @@ unsigned long long GetTotalMemory()
 #if defined(__linux__) && !defined(__ANDROID__)
 #if defined(__linux__) && !defined(__ANDROID__)
     struct sysinfo s;
     struct sysinfo s;
     if (sysinfo(&s) != -1)
     if (sysinfo(&s) != -1)
-        return s.totalram; 
+        return s.totalram;
 #elif defined(_WIN32)
 #elif defined(_WIN32)
     MEMORYSTATUSEX state;
     MEMORYSTATUSEX state;
-    state.dwLength = sizeof(state); 
-    if (GlobalMemoryStatusEx(&state)) 
-        return state.ullTotalPhys; 
+    state.dwLength = sizeof(state);
+    if (GlobalMemoryStatusEx(&state))
+        return state.ullTotalPhys;
 #elif defined(__APPLE__)
 #elif defined(__APPLE__)
     unsigned long long memSize;
     unsigned long long memSize;
     size_t len = sizeof(memSize);
     size_t len = sizeof(memSize);
-    int mib[2]; 
+    int mib[2];
     mib[0] = CTL_HW;
     mib[0] = CTL_HW;
     mib[1] = HW_MEMSIZE;
     mib[1] = HW_MEMSIZE;
     sysctl(mib, 2, &memSize, &len, NULL, 0);
     sysctl(mib, 2, &memSize, &len, NULL, 0);
@@ -536,11 +536,11 @@ unsigned long long GetTotalMemory()
     return 0ull;
     return 0ull;
 }
 }
 
 
-String GetLoginName() 
+String GetLoginName()
 {
 {
 #if defined(__linux__) && !defined(__ANDROID__)
 #if defined(__linux__) && !defined(__ANDROID__)
     struct passwd *p = getpwuid(getuid());
     struct passwd *p = getpwuid(getuid());
-    if (p != NULL) 
+    if (p != nullptr)
         return p->pw_name;
         return p->pw_name;
 #elif defined(_WIN32)
 #elif defined(_WIN32)
     char name[UNLEN + 1];
     char name[UNLEN + 1];
@@ -551,32 +551,32 @@ String GetLoginName()
     SCDynamicStoreRef s = SCDynamicStoreCreate(NULL, CFSTR("GetConsoleUser"), NULL, NULL);
     SCDynamicStoreRef s = SCDynamicStoreCreate(NULL, CFSTR("GetConsoleUser"), NULL, NULL);
     if (s != NULL)
     if (s != NULL)
     {
     {
-        uid_t u; 
+        uid_t u;
         CFStringRef n = SCDynamicStoreCopyConsoleUser(s, &u, NULL);
         CFStringRef n = SCDynamicStoreCopyConsoleUser(s, &u, NULL);
-        CFRelease(s); 
+        CFRelease(s);
         if (n != NULL)
         if (n != NULL)
         {
         {
-            char name[256]; 
+            char name[256];
             Boolean b = CFStringGetCString(n, name, 256, kCFStringEncodingUTF8);
             Boolean b = CFStringGetCString(n, name, 256, kCFStringEncodingUTF8);
-            CFRelease(n); 
+            CFRelease(n);
 
 
             if (b == true)
             if (b == true)
-                return name; 
+                return name;
         }
         }
     }
     }
 #endif
 #endif
     return "(?)";
     return "(?)";
 }
 }
 
 
-String GetHostName() 
+String GetHostName()
 {
 {
 #if (defined(__linux__) || defined(__APPLE__)) && !defined(__ANDROID__)
 #if (defined(__linux__) || defined(__APPLE__)) && !defined(__ANDROID__)
-    char buffer[256]; 
-    if (gethostname(buffer, 256) == 0) 
-        return buffer; 
+    char buffer[256];
+    if (gethostname(buffer, 256) == 0)
+        return buffer;
 #elif defined(_WIN32)
 #elif defined(_WIN32)
-    char buffer[MAX_COMPUTERNAME_LENGTH + 1]; 
-    DWORD len = MAX_COMPUTERNAME_LENGTH + 1; 
+    char buffer[MAX_COMPUTERNAME_LENGTH + 1];
+    DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
     if (GetComputerName(buffer, &len))
     if (GetComputerName(buffer, &len))
         return buffer;
         return buffer;
 #endif
 #endif
@@ -594,59 +594,59 @@ static void GetOS(RTL_OSVERSIONINFOW *r)
     {
     {
         RtlGetVersionPtr fPtr = (RtlGetVersionPtr) GetProcAddress(m, "RtlGetVersion");
         RtlGetVersionPtr fPtr = (RtlGetVersionPtr) GetProcAddress(m, "RtlGetVersion");
         if (r && fPtr && fPtr(r) == 0)
         if (r && fPtr && fPtr(r) == 0)
-            r->dwOSVersionInfoSize = sizeof *r; 
+            r->dwOSVersionInfoSize = sizeof *r;
     }
     }
 }
 }
-#endif 
+#endif
 
 
-String GetOSVersion() 
+String GetOSVersion()
 {
 {
 #if defined(__linux__) && !defined(__ANDROID__)
 #if defined(__linux__) && !defined(__ANDROID__)
     struct utsname u;
     struct utsname u;
     if (uname(&u) == 0)
     if (uname(&u) == 0)
-        return String(u.sysname) + " " + u.release; 
+        return String(u.sysname) + " " + u.release;
 #elif defined(_WIN32) && defined(HAVE_RTL_OSVERSIONINFOW) && !defined(MINI_URHO)
 #elif defined(_WIN32) && defined(HAVE_RTL_OSVERSIONINFOW) && !defined(MINI_URHO)
     RTL_OSVERSIONINFOW r;
     RTL_OSVERSIONINFOW r;
-    GetOS(&r); 
+    GetOS(&r);
     // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
     // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
-    if (r.dwMajorVersion == 5 && r.dwMinorVersion == 0) 
-        return "Windows 2000"; 
-    else if (r.dwMajorVersion == 5 && r.dwMinorVersion == 1) 
-        return "Windows XP"; 
-    else if (r.dwMajorVersion == 5 && r.dwMinorVersion == 2) 
-        return "Windows XP 64-Bit Edition/Windows Server 2003/Windows Server 2003 R2"; 
-    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 0) 
-        return "Windows Vista/Windows Server 2008"; 
-    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 1) 
-        return "Windows 7/Windows Server 2008 R2"; 
-    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 2) 
+    if (r.dwMajorVersion == 5 && r.dwMinorVersion == 0)
+        return "Windows 2000";
+    else if (r.dwMajorVersion == 5 && r.dwMinorVersion == 1)
+        return "Windows XP";
+    else if (r.dwMajorVersion == 5 && r.dwMinorVersion == 2)
+        return "Windows XP 64-Bit Edition/Windows Server 2003/Windows Server 2003 R2";
+    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 0)
+        return "Windows Vista/Windows Server 2008";
+    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 1)
+        return "Windows 7/Windows Server 2008 R2";
+    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 2)
         return "Windows 8/Windows Server 2012";
         return "Windows 8/Windows Server 2012";
-    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 3) 
-        return "Windows 8.1/Windows Server 2012 R2"; 
-    else if (r.dwMajorVersion == 10 && r.dwMinorVersion == 0) 
-        return "Windows 10/Windows Server 2016"; 
-    else 
+    else if (r.dwMajorVersion == 6 && r.dwMinorVersion == 3)
+        return "Windows 8.1/Windows Server 2012 R2";
+    else if (r.dwMajorVersion == 10 && r.dwMinorVersion == 0)
+        return "Windows 10/Windows Server 2016";
+    else
         return "Windows Unknown";
         return "Windows Unknown";
 #elif defined(__APPLE__)
 #elif defined(__APPLE__)
-    char kernel_r[256]; 
-    size_t size = sizeof(kernel_r); 
+    char kernel_r[256];
+    size_t size = sizeof(kernel_r);
 
 
     if (sysctlbyname("kern.osrelease", &kernel_r, &size, NULL, 0) != -1)
     if (sysctlbyname("kern.osrelease", &kernel_r, &size, NULL, 0) != -1)
     {
     {
-        Vector<String> kernel_version = String(kernel_r).Split('.'); 
-        String version = "macOS/Mac OS X "; 
+        Vector<String> kernel_version = String(kernel_r).Split('.');
+        String version = "macOS/Mac OS X ";
         int major = ToInt(kernel_version[0]);
         int major = ToInt(kernel_version[0]);
         int minor = ToInt(kernel_version[1]);
         int minor = ToInt(kernel_version[1]);
 
 
         // https://en.wikipedia.org/wiki/Darwin_(operating_system)
         // https://en.wikipedia.org/wiki/Darwin_(operating_system)
-        if (major == 16) // macOS Sierra 
+        if (major == 16) // macOS Sierra
         {
         {
-            version += "Sierra "; 
+            version += "Sierra ";
             switch(minor)
             switch(minor)
             {
             {
-                case 0: version += "10.12.0 "; break; 
-                case 1: version += "10.12.1 "; break; 
-                case 3: version += "10.12.2 "; break; 
+                case 0: version += "10.12.0 "; break;
+                case 1: version += "10.12.1 "; break;
+                case 3: version += "10.12.2 "; break;
             }
             }
         }
         }
         else if (major == 15) // OS X El Capitan
         else if (major == 15) // OS X El Capitan
@@ -654,17 +654,17 @@ String GetOSVersion()
             version += "El Capitan ";
             version += "El Capitan ";
             switch(minor)
             switch(minor)
             {
             {
-                case 0: version += "10.11.0 "; break; 
-                case 6: version += "10.11.6 "; break; 
+                case 0: version += "10.11.0 "; break;
+                case 6: version += "10.11.6 "; break;
             }
             }
         }
         }
-        else if (major == 14) // OS X Yosemite 
+        else if (major == 14) // OS X Yosemite
         {
         {
-            version += "Yosemite "; 
-            switch(minor) 
+            version += "Yosemite ";
+            switch(minor)
             {
             {
-                case 0: version += "10.10.0 "; break; 
-                case 5: version += "10.10.5 "; break; 
+                case 0: version += "10.10.0 "; break;
+                case 5: version += "10.10.5 "; break;
             }
             }
         }
         }
         else if (major == 13) // OS X Mavericks
         else if (major == 13) // OS X Mavericks
@@ -672,17 +672,17 @@ String GetOSVersion()
             version += "Mavericks ";
             version += "Mavericks ";
             switch(minor)
             switch(minor)
             {
             {
-                case 0: version += "10.9.0 "; break; 
-                case 4: version += "10.9.5 "; break; 
+                case 0: version += "10.9.0 "; break;
+                case 4: version += "10.9.5 "; break;
             }
             }
         }
         }
         else if (major == 12) // OS X Mountain Lion
         else if (major == 12) // OS X Mountain Lion
         {
         {
-            version += "Mountain Lion "; 
-            switch(minor) 
+            version += "Mountain Lion ";
+            switch(minor)
             {
             {
-                case 0: version += "10.8.0 "; break; 
-                case 6: version += "10.8.5 "; break; 
+                case 0: version += "10.8.0 "; break;
+                case 6: version += "10.8.5 "; break;
             }
             }
         }
         }
         else if (major == 11) // Mac OS X Lion
         else if (major == 11) // Mac OS X Lion
@@ -690,16 +690,16 @@ String GetOSVersion()
             version += "Lion ";
             version += "Lion ";
             switch(minor)
             switch(minor)
             {
             {
-                case 0: version += "10.7.0 "; break; 
-                case 4: version += "10.7.5 "; break; 
+                case 0: version += "10.7.0 "; break;
+                case 4: version += "10.7.5 "; break;
             }
             }
         }
         }
-        else 
+        else
         {
         {
             version += "Unknown ";
             version += "Unknown ";
         }
         }
 
 
-        return version + " (Darwin kernel " + kernel_version[0] + "." + kernel_version[1] + "." + kernel_version[2] + ")"; 
+        return version + " (Darwin kernel " + kernel_version[0] + "." + kernel_version[1] + "." + kernel_version[2] + ")";
     }
     }
 #endif
 #endif
     return "(?)";
     return "(?)";

+ 3 - 3
Source/Urho3D/Core/Thread.cpp

@@ -51,8 +51,8 @@ static void* ThreadFunctionStatic(void* data)
 {
 {
     auto* thread = static_cast<Thread*>(data);
     auto* thread = static_cast<Thread*>(data);
     thread->ThreadFunction();
     thread->ThreadFunction();
-    pthread_exit((void*)0);
-    return 0;
+    pthread_exit((void*)nullptr);
+    return nullptr;
 }
 }
 
 
 #endif
 #endif
@@ -108,7 +108,7 @@ void Thread::Stop()
 #else
 #else
     auto* thread = (pthread_t*)handle_;
     auto* thread = (pthread_t*)handle_;
     if (thread)
     if (thread)
-        pthread_join(*thread, 0);
+        pthread_join(*thread, nullptr);
     delete thread;
     delete thread;
 #endif
 #endif
     handle_ = nullptr;
     handle_ = nullptr;

+ 3 - 3
Source/Urho3D/Core/Timer.cpp

@@ -77,7 +77,7 @@ static unsigned Tick()
     return (unsigned)emscripten_get_now();
     return (unsigned)emscripten_get_now();
 #else
 #else
     struct timeval time;
     struct timeval time;
-    gettimeofday(&time, NULL);
+    gettimeofday(&time, nullptr);
     return (unsigned)(time.tv_sec * 1000 + time.tv_usec / 1000);
     return (unsigned)(time.tv_sec * 1000 + time.tv_usec / 1000);
 #endif
 #endif
 }
 }
@@ -97,7 +97,7 @@ static long long HiresTick()
     return (unsigned)(emscripten_get_now()*1000.0);
     return (unsigned)(emscripten_get_now()*1000.0);
 #else
 #else
     struct timeval time;
     struct timeval time;
-    gettimeofday(&time, NULL);
+    gettimeofday(&time, nullptr);
     return time.tv_sec * 1000000LL + time.tv_usec;
     return time.tv_sec * 1000000LL + time.tv_usec;
 #endif
 #endif
 }
 }
@@ -185,7 +185,7 @@ void Time::Sleep(unsigned mSec)
     timespec time;
     timespec time;
     time.tv_sec = mSec / 1000;
     time.tv_sec = mSec / 1000;
     time.tv_nsec = (mSec % 1000) * 1000000;
     time.tv_nsec = (mSec % 1000) * 1000000;
-    nanosleep(&time, 0);
+    nanosleep(&time, nullptr);
 #endif
 #endif
 }
 }
 
 

+ 1 - 1
Source/Urho3D/Database/SQLite/SQLiteConnection.h

@@ -53,7 +53,7 @@ public:
     const sqlite3* GetConnectionImpl() const { return connectionImpl_; }
     const sqlite3* GetConnectionImpl() const { return connectionImpl_; }
 
 
     /// Return true when the connection object is connected to the associated database.
     /// Return true when the connection object is connected to the associated database.
-    bool IsConnected() const { return connectionImpl_ != 0; }
+    bool IsConnected() const { return connectionImpl_ != nullptr; }
 
 
 private:
 private:
     /// The connection string for SQLite3 is using the URI format described in https://www.sqlite.org/uri.html, while the connection string for ODBC is using DSN format as per ODBC standard.
     /// The connection string for SQLite3 is using the URI format described in https://www.sqlite.org/uri.html, while the connection string for ODBC is using DSN format as per ODBC standard.

+ 1 - 1
Source/Urho3D/Graphics/Renderer.cpp

@@ -1088,7 +1088,7 @@ Texture* Renderer::GetScreenBuffer(int width, int height, unsigned format, int m
                 // Note: this loses current rendertarget assignment
                 // Note: this loses current rendertarget assignment
                 graphics_->ResetRenderTargets();
                 graphics_->ResetRenderTargets();
                 graphics_->SetRenderTarget(0, newTex2D);
                 graphics_->SetRenderTarget(0, newTex2D);
-                graphics_->SetDepthStencil((RenderSurface*)0);
+                graphics_->SetDepthStencil((RenderSurface*)nullptr);
                 graphics_->SetViewport(IntRect(0, 0, width, height));
                 graphics_->SetViewport(IntRect(0, 0, width, height));
                 graphics_->Clear(CLEAR_COLOR);
                 graphics_->Clear(CLEAR_COLOR);
             }
             }

+ 2 - 2
Source/Urho3D/IK/IKSolver.cpp

@@ -235,7 +235,7 @@ ik_node_t* IKSolver::CreateIKNodeFromUrhoNode(const Node* node)
     if (effector != nullptr)
     if (effector != nullptr)
     {
     {
 #ifdef DEBUG
 #ifdef DEBUG
-        if (effector->ikEffectorNode_ != NULL)
+        if (effector->ikEffectorNode_ != nullptr)
             URHO3D_LOGWARNINGF("[ik] IKEffector (attached to node \"%s\") has a reference to a possibly invalid internal effector. Should be NULL.", effector->GetNode()->GetName().CString());
             URHO3D_LOGWARNINGF("[ik] IKEffector (attached to node \"%s\") has a reference to a possibly invalid internal effector. Should be NULL.", effector->GetNode()->GetName().CString());
 #endif
 #endif
         ik_effector_t* ikEffector = ik_effector_create();
         ik_effector_t* ikEffector = ik_effector_create();
@@ -250,7 +250,7 @@ ik_node_t* IKSolver::CreateIKNodeFromUrhoNode(const Node* node)
     if (constraint != nullptr)
     if (constraint != nullptr)
     {
     {
 #ifdef DEBUG
 #ifdef DEBUG
-        if (constraint->ikConstraintNode_ != NULL)
+        if (constraint->ikConstraintNode_ != nullptr)
             URHO3D_LOGWARNINGF("[ik] IKConstraint (attached to node \"%s\") has a reference to a possibly invalid internal constraint. Should be NULL.", constraint->GetNode()->GetName().CString());
             URHO3D_LOGWARNINGF("[ik] IKConstraint (attached to node \"%s\") has a reference to a possibly invalid internal constraint. Should be NULL.", constraint->GetNode()->GetName().CString());
 #endif
 #endif
 
 

+ 1 - 1
Source/Urho3D/IO/NamedPipe.cpp

@@ -370,7 +370,7 @@ bool NamedPipe::IsEof() const
         timeout.tv_sec = 0;
         timeout.tv_sec = 0;
         timeout.tv_usec = 1000; // 1ms timeout for select
         timeout.tv_usec = 1000; // 1ms timeout for select
 
 
-        return select(readHandle_ + 1, &set, 0, 0, &timeout) <= 0;
+        return select(readHandle_ + 1, &set, nullptr, nullptr, &timeout) <= 0;
     }
     }
     else
     else
         return true;
         return true;