From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32293 invoked by alias); 7 Mar 2013 23:54:15 -0000 Received: (qmail 32234 invoked by uid 22791); 7 Mar 2013 23:54:13 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Mar 2013 23:54:03 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r27Ns2kB030277 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 7 Mar 2013 18:54:02 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r27Ns1wH010004 for ; Thu, 7 Mar 2013 18:54:02 -0500 Subject: [COMMIT PATCH] target.c: fix -Wpointer-sign To: gdb-patches@sourceware.org From: Pedro Alves Date: Thu, 07 Mar 2013 23:54:00 -0000 Message-ID: <20130307235401.23019.61535.stgit@brno.lan> User-Agent: StGit/0.16 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2013-03/txt/msg00321.txt.bz2 $ make WERROR_CFLAGS="-Wpointer-sign -Werror" target.o -k 2>&1 1>/dev/null ../../src/gdb/target.c: In function ‘target_read_stralloc’: ../../src/gdb/target.c:2376:3: error: pointer targets in passing argument 1 of ‘strlen’ differ in signedness [-Werror=pointer-sign] In file included from build-gnulib/import/string.h:27:0, from ../../src/gdb/common/gdb_string.h:24, from ../../src/gdb/target.c:24: /usr/include/string.h:399:15: note: expected ‘const char *’ but argument is of type ‘gdb_byte *’ ../../src/gdb/target.c: In function ‘target_fileio_read_stralloc’: ... This is about the same as the previous patch. Functions that take or return ascii-ish string arguments usually use char* for parameters/return. That means that at points we call into target methods that work with binary blobs, we need casts to/from gdb_byte*/char*. To choose which type for the variables, I usually go based on which requires the fewer casts, and what the contents of the variable are supposed to hold, which often gives the same answer. gdb/ 2013-03-07 Pedro Alves * target.c (target_read_stralloc, target_fileio_read_alloc): *Cast pointer to 'gdb_byte *' in target call. --- gdb/target.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gdb/target.c b/gdb/target.c index ecb1325..eaf8b31 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2359,10 +2359,11 @@ char * target_read_stralloc (struct target_ops *ops, enum target_object object, const char *annex) { - gdb_byte *buffer; + char *buffer; LONGEST i, transferred; - transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1); + transferred = target_read_alloc_1 (ops, object, annex, + (gdb_byte **) &buffer, 1); if (transferred < 0) return NULL; @@ -2382,7 +2383,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object, break; } - return (char *) buffer; + return buffer; } /* Memory transfer methods. */ @@ -3522,10 +3523,11 @@ target_fileio_read_alloc (const char *filename, gdb_byte **buf_p) char * target_fileio_read_stralloc (const char *filename) { - gdb_byte *buffer; + char *buffer; LONGEST i, transferred; - transferred = target_fileio_read_alloc_1 (filename, &buffer, 1); + transferred = target_fileio_read_alloc_1 (filename, + (gdb_byte **) &buffer, 1); if (transferred < 0) return NULL; @@ -3545,7 +3547,7 @@ target_fileio_read_stralloc (const char *filename) break; } - return (char *) buffer; + return buffer; }