[CRIU] [PATCH 1/8] util: Add read_string helper
Andrew Vagin
avagin at parallels.com
Thu May 10 03:04:52 EDT 2012
On Sat, May 05, 2012 at 07:20:17PM +0400, Cyrill Gorcunov wrote:
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> include/util.h | 7 +++++++
> 1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/include/util.h b/include/util.h
> index 5172a88..62e3877 100644
> --- a/include/util.h
> +++ b/include/util.h
> @@ -132,6 +132,13 @@ static inline int read_img_buf(int fd, void *ptr, int size)
> #define memzero_p(p) memset(p, 0, sizeof(*p))
> #define memzero(p, size) memset(p, 0, size)
>
> +static inline int read_string(int fd, char *ptr, int size)
> +{
> + int ret = read(fd, ptr, size);
> + ptr[ret > 0 ? ret - 1 : 0] = '\0';
I don't like it, the last symbol may be non-zero, but we set it to zero,
it may hide a problem.
if (ret < 0)
return ret;
else if (ret == size) {
if (ptr[ret - 1] != '\0')
return -ENOMEM;
return ret;
} else
ptr[ret] = '\0';
Why can you not use my decision for similar cases?
I think we should have one method for one type of problems.
I agree with both of them, so you should chage it everywhere.
> + return ret;
> +}
> +
> struct vma_area;
> struct list_head;
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list