[lxc-devel] [PATCH lxcfs 2/5] avoid strlen in must_strcat_pid
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Jan 7 11:59:52 UTC 2016
sprintf() already returns the length
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
lxcfs.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxcfs.c b/lxcfs.c
index 767a344..8605000 100644
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -77,7 +77,7 @@ static void must_strcat_pid(char **src, size_t *sz, size_t *asz, pid_t pid)
char *d = *src;
char tmp[30];
- sprintf(tmp, "%d\n", (int)pid);
+ int tmplen = sprintf(tmp, "%d\n", (int)pid);
if (!d) {
do {
@@ -85,15 +85,15 @@ static void must_strcat_pid(char **src, size_t *sz, size_t *asz, pid_t pid)
} while (!d);
*src = d;
*asz = BUF_RESERVE_SIZE;
- } else if (strlen(tmp) + *sz + 1 >= *asz) {
+ } else if (tmplen + *sz + 1 >= *asz) {
do {
d = realloc(d, *asz + BUF_RESERVE_SIZE);
} while (!d);
*src = d;
*asz += BUF_RESERVE_SIZE;
}
- memcpy(d+*sz, tmp, strlen(tmp));
- *sz += strlen(tmp);
+ memcpy(d+*sz, tmp, tmplen);
+ *sz += tmplen;
d[*sz] = '\0';
}
--
2.1.4
More information about the lxc-devel
mailing list