From patchwork Tue Apr 4 17:25:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 19824 Received: (qmail 106142 invoked by alias); 4 Apr 2017 17:25:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 105840 invoked by uid 89); 4 Apr 2017 17:25:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=9847, 538 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Apr 2017 17:25:57 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DBABF7AE93 for ; Tue, 4 Apr 2017 17:25:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DBABF7AE93 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DBABF7AE93 Received: from cascais.lan (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 643EC18247 for ; Tue, 4 Apr 2017 17:25:57 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 02/18] -Wwrite-strings: Constify macroexp.c:init_shared_buffer Date: Tue, 4 Apr 2017 18:25:35 +0100 Message-Id: <1491326751-16180-3-git-send-email-palves@redhat.com> In-Reply-To: <1491326751-16180-1-git-send-email-palves@redhat.com> References: <1491326751-16180-1-git-send-email-palves@redhat.com> There's one call in the file that passes a string literal, like: init_shared_buffer (&va_arg_name, "__VA_ARGS__", strlen ("__VA_ARGS__")); Instead of adding a cast here, make init_shared_buffer take a 'const char *', and remove the several casts in the file that are made obsolete. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * macroexp.c (macro_buffer::shared): Now a bool. (init_buffer): Update. (init_shared_buffer): Constify 'addr' parameter. (substitute_args, expand, macro_expand, macro_expand_next): Remove casts. --- gdb/macroexp.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/gdb/macroexp.c b/gdb/macroexp.c index 3cc2d0b..5537d9d 100644 --- a/gdb/macroexp.c +++ b/gdb/macroexp.c @@ -53,8 +53,9 @@ struct macro_buffer /* Zero if TEXT can be safely realloc'ed (i.e., it's its own malloc block). Non-zero if TEXT is actually pointing into the middle of - some other block, and we shouldn't reallocate it. */ - int shared; + some other block, or to a string literal, and we shouldn't + reallocate it. */ + bool shared; /* For detecting token splicing. @@ -85,19 +86,22 @@ init_buffer (struct macro_buffer *b, int n) else b->text = NULL; b->len = 0; - b->shared = 0; + b->shared = false; b->last_token = -1; } /* Set the macro buffer *BUF to refer to the LEN bytes at ADDR, as a shared substring. */ + static void -init_shared_buffer (struct macro_buffer *buf, char *addr, int len) +init_shared_buffer (struct macro_buffer *buf, const char *addr, int len) { - buf->text = addr; + /* The function accept a "const char *" addr so that clients can + pass in string literals without casts. */ + buf->text = (char *) addr; buf->len = len; - buf->shared = 1; + buf->shared = true; buf->size = 0; buf->last_token = -1; } @@ -980,7 +984,7 @@ substitute_args (struct macro_buffer *dest, lexed. */ char *lookahead_rl_start; - init_shared_buffer (&replacement_list, (char *) def->replacement, + init_shared_buffer (&replacement_list, def->replacement, strlen (def->replacement)); gdb_assert (dest->len == 0); @@ -1199,7 +1203,7 @@ expand (const char *id, { struct macro_buffer replacement_list; - init_shared_buffer (&replacement_list, (char *) def->replacement, + init_shared_buffer (&replacement_list, def->replacement, strlen (def->replacement)); scan (dest, &replacement_list, &new_no_loop, lookup_func, lookup_baton); @@ -1236,7 +1240,7 @@ expand (const char *id, substitution parameter is the name of the formal argument without the "...". */ init_shared_buffer (&va_arg_name, - (char *) def->argv[def->argc - 1], + def->argv[def->argc - 1], len - 3); is_varargs = 1; } @@ -1415,7 +1419,7 @@ macro_expand (const char *source, struct macro_buffer src, dest; struct cleanup *back_to; - init_shared_buffer (&src, (char *) source, strlen (source)); + init_shared_buffer (&src, source, strlen (source)); init_buffer (&dest, 0); dest.last_token = 0; @@ -1448,7 +1452,7 @@ macro_expand_next (const char **lexptr, struct cleanup *back_to; /* Set up SRC to refer to the input text, pointed to by *lexptr. */ - init_shared_buffer (&src, (char *) *lexptr, strlen (*lexptr)); + init_shared_buffer (&src, *lexptr, strlen (*lexptr)); /* Set up DEST to receive the expansion, if there is one. */ init_buffer (&dest, 0);