From patchwork Fri Aug 21 21:24:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 8378 Received: (qmail 122340 invoked by alias); 21 Aug 2015 21:24:12 -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 122327 invoked by uid 89); 21 Aug 2015 21:24:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 21 Aug 2015 21:24:10 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 78370224 for ; Fri, 21 Aug 2015 21:24:09 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7LLO8CA020829 for ; Fri, 21 Aug 2015 17:24:08 -0400 Subject: [PATCH v12 30/32] Code cleanup: New hex2bin_allocate() From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Fri, 21 Aug 2015 23:24:07 +0200 Message-ID: <20150821212407.6673.35658.stgit@host1.jankratochvil.net> In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> References: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes Hi, make hex->bin parsing standalone, to be reused in later patch. Jan gdb/ChangeLog 2015-08-20 Jan Kratochvil * solib-svr4.c (hex2bin_allocate): New function from ... (library_list_start_library): ... here, call it. --- 0 files changed diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 8739c31..c725683 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -1160,6 +1160,47 @@ svr4_copy_library_list (struct so_list *src) #include "xml-support.h" +/* Conver text hexadecimal representation HEX into its binary form, + store it to newly allocated memory *BINP sized *BINSZP. For errors + reporting use FILENAME. */ + +static void +hex2bin_allocate (const char *hex, gdb_byte **binp, size_t *binszp, + const char *filename) +{ + size_t hex_len, binsz; + + if (hex == NULL) + return; + hex_len = strlen (hex); + if (hex_len == 0) + { + warning (_("Shared library \"%s\" received empty build-id " + "from gdbserver"), filename); + return; + } + if ((hex_len & 1U) != 0) + { + warning (_("Shared library \"%s\" received odd number " + "of build-id \"%s\" hex characters from gdbserver"), + filename, hex); + return; + } + binsz = hex_len / 2; + *binp = xmalloc (binsz); + *binszp = hex2bin (hex, *binp, binsz); + if (*binszp != binsz) + { + warning (_("Shared library \"%s\" received invalid " + "build-id \"%s\" hex character at encoded byte " + "position %s (first as 0) from gdbserver"), + filename, hex, pulongest (*binszp)); + xfree (*binp); + *binp = NULL; + *binszp = 0; + } +} + /* Handle the start of a element. Note: new elements are added at the tail of the list, keeping the list in order. */ @@ -1187,37 +1228,8 @@ library_list_start_library (struct gdb_xml_parser *parser, strncpy (new_elem->so_name, name, sizeof (new_elem->so_name) - 1); new_elem->so_name[sizeof (new_elem->so_name) - 1] = 0; strcpy (new_elem->so_original_name, new_elem->so_name); - if (hex_build_id != NULL) - { - const size_t hex_build_id_len = strlen (hex_build_id); - - if (hex_build_id_len == 0) - warning (_("Shared library \"%s\" received empty build-id " - "from gdbserver"), new_elem->so_original_name); - else if ((hex_build_id_len & 1U) != 0) - warning (_("Shared library \"%s\" received odd number " - "of build-id \"%s\" hex characters from gdbserver"), - new_elem->so_original_name, hex_build_id); - else - { - const size_t build_idsz = hex_build_id_len / 2; - - new_elem->build_id = xmalloc (build_idsz); - new_elem->build_idsz = hex2bin (hex_build_id, new_elem->build_id, - build_idsz); - if (new_elem->build_idsz != build_idsz) - { - warning (_("Shared library \"%s\" received invalid " - "build-id \"%s\" hex character at encoded byte " - "position %s (first as 0) from gdbserver"), - new_elem->so_original_name, hex_build_id, - pulongest (new_elem->build_idsz)); - xfree (new_elem->build_id); - new_elem->build_id = NULL; - new_elem->build_idsz = 0; - } - } - } + hex2bin_allocate (hex_build_id, &new_elem->build_id, &new_elem->build_idsz, + new_elem->so_original_name); *list->tailp = new_elem; list->tailp = &new_elem->next;