Resolve using of auto that causes a copy 56/316856/2
authorYonggoo Kang <ygace.kang@samsung.com>
Thu, 29 Aug 2024 11:15:08 +0000 (20:15 +0900)
committerYonggoo Kang <ygace.kang@samsung.com>
Thu, 29 Aug 2024 11:26:23 +0000 (20:26 +0900)
- Avoid unnecessary object copies can affect performance
- CID 1789326 from coverity check

Change-Id: I74ea483e117009b7c2a6960e68edb07134a72b7a

srcs/common/utils.cpp

index fb796c53e187e35f4808ac61ff7e3c34eef54625..d8ad898ff896d31fbf48c2b62e1a4dff99407841 100644 (file)
@@ -125,7 +125,7 @@ void CheckParameters(const wauthn_pubkey_cred_params_s *pubkey_cred_params)
         ThrowMsg(ClientException::InvalidParameter, "pubkey_cred_params->size is 0");
     for (size_t i = 0; i < pubkey_cred_params->size; ++i)
     {
-        auto param = pubkey_cred_params->params[i];
+        const auto &param = pubkey_cred_params->params[i];
         CheckParameters(param.type);
         CheckParameters(param.alg);
     }
@@ -149,7 +149,7 @@ void CheckParameters(const wauthn_pubkey_cred_descriptors_s *cred_descriptors)
                  "cred_descriptors->descriptors is not NULL and size is 0");
     for (size_t i = 0; i < cred_descriptors->size; ++i)
     {
-        auto desc = cred_descriptors->descriptors[i];
+        const auto &desc = cred_descriptors->descriptors[i];
         CheckParameters(desc.type);
         CheckParameters(desc.id, "descriptor->id");
         CheckParameters(desc.transports);
@@ -229,7 +229,7 @@ void CheckParameters(const wauthn_pubkey_cred_hints_s *hints)
                  "hints->hints is not NULL and size is 0");
     for (size_t i = 0; i < hints->size; ++i)
     {
-        auto hint = hints->hints[i];
+        const auto &hint = hints->hints[i];
         CheckParameters(hint);
     }
 }
@@ -258,7 +258,7 @@ void CheckParameters(const wauthn_attestation_formats_s *attestation_formats)
                  "attestation_formats->attestation_formats is not NULL and size is 0");
     for (size_t i = 0; i < attestation_formats->size; ++i)
     {
-        auto format = attestation_formats->attestation_formats[i];
+        const auto &format = attestation_formats->attestation_formats[i];
         CheckParameters(format, "attestation_format");
     }
 }
@@ -279,7 +279,7 @@ void CheckParameters(const wauthn_authentication_exts_s *extensions)
     }
     for (size_t i = 0; i < extensions->size; ++i)
     {
-        auto extension = extensions->extensions[i];
+        const auto &extension = extensions->extensions[i];
         CheckParameters(extension.extension_id, "extension id");
         CheckParameters(extension.extension_value, "extension value");
     }