From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13284 invoked by alias); 19 Oct 2016 01:17:46 -0000 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 Received: (qmail 13201 invoked by uid 89); 19 Oct 2016 01:17:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy=Modify 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; Wed, 19 Oct 2016 01:17:44 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1198A3B716 for ; Wed, 19 Oct 2016 01:12:30 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9J1CJjf019701 for ; Tue, 18 Oct 2016 21:12:29 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 10/31] Use ui_file_as_string in gdb/ada-valprint.c Date: Wed, 19 Oct 2016 01:17:00 -0000 Message-Id: <1476839539-8374-11-git-send-email-palves@redhat.com> In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com> References: <1476839539-8374-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-10/txt/msg00545.txt.bz2 gdb/ChangeLog: yyyy-mm-yy Pedro Alves * ada-valprint.c (ada_print_floating): Use ui_file_as_string and std::string. --- gdb/ada-valprint.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c index 6b4b6d4..bae4e4f 100644 --- a/gdb/ada-valprint.c +++ b/gdb/ada-valprint.c @@ -298,49 +298,50 @@ static void ada_print_floating (const gdb_byte *valaddr, struct type *type, struct ui_file *stream) { - char *s, *result; struct ui_file *tmp_stream = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream); print_floating (valaddr, type, tmp_stream); - result = ui_file_xstrdup (tmp_stream, NULL); - make_cleanup (xfree, result); + + std::string s = ui_file_as_string (tmp_stream); + size_t skip_count = 0; /* Modify for Ada rules. */ - s = strstr (result, "inf"); - if (s == NULL) - s = strstr (result, "Inf"); - if (s == NULL) - s = strstr (result, "INF"); - if (s != NULL) - strcpy (s, "Inf"); + size_t pos = s.find ("inf"); + if (pos == std::string::npos) + pos = s.find ("Inf"); + if (pos == std::string::npos) + pos = s.find ("INF"); + if (pos != std::string::npos) + s.replace (pos, 3, "Inf"); - if (s == NULL) + if (pos == std::string::npos) { - s = strstr (result, "nan"); - if (s == NULL) - s = strstr (result, "NaN"); - if (s == NULL) - s = strstr (result, "Nan"); - if (s != NULL) + pos = s.find ("nan"); + if (pos == std::string::npos) + pos = s.find ("NaN"); + if (pos == std::string::npos) + pos = s.find ("Nan"); + if (pos != std::string::npos) { - s[0] = s[2] = 'N'; - if (result[0] == '-') - result += 1; + s[pos] = s[pos + 2] = 'N'; + if (s[0] == '-') + skip_count = 1; } } - if (s == NULL && strchr (result, '.') == NULL) + if (pos == std::string::npos + && s.find ('.') == std::string::npos) { - s = strchr (result, 'e'); - if (s == NULL) - fprintf_filtered (stream, "%s.0", result); + pos = s.find ('e'); + if (pos == std::string::npos) + fprintf_filtered (stream, "%s.0", s.c_str ()); else - fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s); + fprintf_filtered (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]); } else - fprintf_filtered (stream, "%s", result); + fprintf_filtered (stream, "%s", &s[skip_count]); do_cleanups (cleanups); } -- 2.5.5