[lxc-devel] [PATCH lxcfs 2/5] avoid strlen in must_strcat_pid
Serge Hallyn
serge.hallyn at ubuntu.com
Thu Jan 7 18:37:32 UTC 2016
Quoting Wolfgang Bumiller (w.bumiller at proxmox.com):
> sprintf() already returns the length
>
> Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.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
>
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
More information about the lxc-devel
mailing list