From: Maciej Słodczyk Date: Wed, 27 May 2020 11:00:25 +0000 (+0200) Subject: avoid truncate string warning when copying X-Git-Tag: submit/tizen/20200602.140231^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen;p=platform%2Fcore%2Fsystem%2Fresourced-headless.git avoid truncate string warning when copying Deliberately copying substring with strncpy() resulted in 'output may be truncated' warning. Use memcpy() to achieve the same without the warning. Change-Id: I8759159e9dd823e78001d4812c52cf2e8588c4e0 Signed-off-by: Maciej Słodczyk --- diff --git a/src/common/procfs.c b/src/common/procfs.c index 12698cb..b59ed93 100644 --- a/src/common/procfs.c +++ b/src/common/procfs.c @@ -460,7 +460,7 @@ API int procfs_get_pid_stat(pid_t pid, struct procfs_pid_stat *pps) { FILE *fp = NULL; char buf[BUF_SIZE]; - char comm[BUF_SIZE]; + char comm[BUF_SIZE] = {}; if (pid < 1 || !pps) { _E("Invalid parameter"); @@ -484,7 +484,7 @@ API int procfs_get_pid_stat(pid_t pid, struct procfs_pid_stat *pps) fclose(fp); return -ENOENT; } - strncpy(pps->comm, comm, COMM_SIZE - 1); + memcpy(pps->comm, comm, COMM_SIZE - 1); pps->comm[COMM_SIZE - 1] = '\0'; fclose(fp);