On 12/16/2014 06:55 PM, Kamil Dudka wrote: > On Tuesday 16 December 2014 17:50:24 Bernhard Voelker wrote: >> - cp = obstack_next_free (xhdr->stk) - xhdr->string_length - p - 1; >> + cp = obstack_next_free (xhdr->stk); >> + cp -= xhdr->string_length - p - 1;
> 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? drats, right. Thanks for the review. For better readability, I'd prefer the += operator as proposed below. Have a nice day, Berny >From 9b50c39a9289cd80547f185d3c52f0ff30167c82 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker <[email protected]> Date: Tue, 16 Dec 2014 20:36:06 +0100 Subject: [PATCH] xheader: avoid pointer-arith warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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..7d5187d 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++ = ' '; -- 2.1.2
