bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-tar] [PATCH] xheader: avoid pointer-arith warning


From: Kamil Dudka
Subject: Re: [Bug-tar] [PATCH] xheader: avoid pointer-arith warning
Date: Tue, 16 Dec 2014 18:55:25 +0100
User-agent: KMail/4.14.3 (Linux/3.17.6-300.fc21.x86_64; KDE/4.14.3; x86_64; ; )

On Tuesday 16 December 2014 17:50:24 Bernhard Voelker wrote:
> GCC-4.8.3 (on openSUSE-13.2) gives the following warnings:
> 
> xheader.c: In function ‘xheader_string_end’:
> xheader.c:1030:38: error: pointer of type ‘void *’ used in arithmetic
> [-Werror=pointer-arith] cp = obstack_next_free (xhdr->stk) -
> xhdr->string_length - p - 1; ^
> xheader.c:1030:60: error: pointer of type ‘void *’ used in arithmetic
> [-Werror=pointer-arith] cp = obstack_next_free (xhdr->stk) -
> xhdr->string_length - p - 1; ^
> xheader.c:1030:64: error: pointer of type ‘void *’ used in arithmetic
> [-Werror=pointer-arith] cp = obstack_next_free (xhdr->stk) -
> xhdr->string_length - p - 1; ^
> * src/xheader.c (xheader_string_end): Split calcuation to avoid the
> above warning.
> ---
>  src/xheader.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/xheader.c b/src/xheader.c
> index b7a54a6..8bcd9ae 100644
> --- a/src/xheader.c
> +++ b/src/xheader.c
> @@ -1027,7 +1027,8 @@ xheader_string_end (struct xheader *xhdr, char const
> *keyword) }
>    x_obstack_blank (xhdr, p);
>    x_obstack_1grow (xhdr, '\n');
> -  cp = obstack_next_free (xhdr->stk) - xhdr->string_length - p - 1;
> +  cp = obstack_next_free (xhdr->stk);
> +  cp -= xhdr->string_length - p - 1;
>    memmove (cp + p, cp, xhdr->string_length);
>    cp = stpcpy (cp, np);
>    *cp++ = ' ';

How are you confirming that it will not change semantics of the original code?

Did not you want to write "cp -= xhdr->string_length + p + 1" instead?

Kamil



reply via email to

[Prev in Thread] Current Thread [Next in Thread]