From: Yunhee Seo Date: Mon, 15 Jul 2024 11:47:57 +0000 (+0900) Subject: libcommon: Modify the length of strncmp parameter X-Git-Tag: accepted/tizen/unified/20240716.140309^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F69%2F314569%2F1;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git libcommon: Modify the length of strncmp parameter 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 --- diff --git a/src/libcommon/proc.c b/src/libcommon/proc.c index 16c439f..12ea071 100644 --- a/src/libcommon/proc.c +++ b/src/libcommon/proc.c @@ -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;