Răsfoiți Sursa

service/sm: Slightly more efficient string name validation

We can check the end of the string first for null-termination, rather
than the beginning of the string.
Lioncash 5 ani în urmă
părinte
comite
057aa6275d
1 a modificat fișierele cu 2 adăugiri și 2 ștergeri
  1. 2 2
      src/core/hle/service/sm/sm.cpp

+ 2 - 2
src/core/hle/service/sm/sm.cpp

@@ -27,11 +27,11 @@ void ServiceManager::InvokeControlRequest(Kernel::HLERequestContext& context) {
 }
 }
 
 
 static ResultCode ValidateServiceName(const std::string& name) {
 static ResultCode ValidateServiceName(const std::string& name) {
-    if (name.size() <= 0 || name.size() > 8) {
+    if (name.empty() || name.size() > 8) {
         LOG_ERROR(Service_SM, "Invalid service name! service={}", name);
         LOG_ERROR(Service_SM, "Invalid service name! service={}", name);
         return ERR_INVALID_NAME;
         return ERR_INVALID_NAME;
     }
     }
-    if (name.find('\0') != std::string::npos) {
+    if (name.rfind('\0') != std::string::npos) {
         LOG_ERROR(Service_SM, "A non null terminated service was passed");
         LOG_ERROR(Service_SM, "A non null terminated service was passed");
         return ERR_INVALID_NAME;
         return ERR_INVALID_NAME;
     }
     }