Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/zbxcommon/common_str.c')
-rw-r--r--src/libs/zbxcommon/common_str.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/libs/zbxcommon/common_str.c b/src/libs/zbxcommon/common_str.c
index 7d59e6faa33..df64d6fe9b2 100644
--- a/src/libs/zbxcommon/common_str.c
+++ b/src/libs/zbxcommon/common_str.c
@@ -125,17 +125,21 @@ char *zbx_dsprintf(char *dest, const char *f, ...)
******************************************************************************/
size_t zbx_strlcpy(char *dst, const char *src, size_t siz)
{
- const char *s = src;
+ size_t len = strlen(src);
- if (0 != siz)
+ if (len + 1 <= siz)
{
- while (0 != --siz && '\0' != *s)
- *dst++ = *s++;
-
- *dst = '\0';
+ memcpy(dst, src, len + 1);
+ return len;
}
- return s - src; /* count does not include null */
+ if (0 == siz)
+ return 0;
+
+ memcpy(dst, src, siz - 1);
+ dst[siz - 1] = '\0';
+
+ return siz - 1;
}
/******************************************************************************