libcommon: Modify the length of strncmp parameter 69/314569/1 accepted/tizen/unified/20240716.140309 accepted/tizen/unified/dev/20240717.110333 accepted/tizen/unified/x/20240717.012500
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 15 Jul 2024 11:47:57 +0000 (20:47 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Mon, 15 Jul 2024 11:47:57 +0000 (20:47 +0900)
When comparing two strings, it is not clear what values are contained in the case where they are obtained from an array.
Thus, using sizeof literal is more clear in terms of readability and maintenance.
This is meaningful especially when the array does not contain proper values or is empty.

Change-Id: Ic427c15767640c20a3e6aaaaa68763a66085ef64
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/libcommon/proc.c

index 16c439f5d8f882f0e3cbf5e05d21970b0f6f97ed..12ea0719184ec246782b0dc7ad246c74103e15c6 100644 (file)
@@ -79,7 +79,6 @@ int syscommon_proc_get_attr_current(pid_t pid, char *buf, int len)
 int syscommon_proc_is_app(pid_t pid)
 {
        char attr[NAME_MAX] = { 0 ,};
-       size_t len = 0;
        int ret = 0;
 
        ret = syscommon_proc_get_attr_current(pid, attr, sizeof(attr));
@@ -88,15 +87,13 @@ int syscommon_proc_is_app(pid_t pid)
                return -1;
        }
 
-       len = strlen(attr) + 1;
-
-       if (!strncmp("System", attr, len))
+       if (!strncmp("System", attr, sizeof("System")))
                return 0;
 
-       if (!strncmp("User", attr, len))
+       if (!strncmp("User", attr, sizeof("User")))
                return 0;
 
-       if (!strncmp("System::Privileged", attr, len))
+       if (!strncmp("System::Privileged", attr, sizeof("System::Privileged")))
                return 0;
 
        return 1;