From patchwork Sat Oct 14 08:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 152917 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2370170vqb; Sat, 14 Oct 2023 01:38:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkAvy8vlsBd8gG+kL0wWXHIlJkwujlCsMmog9cLwOZ5H/SArJk9gc9lx98YMIm6bdIJBz2 X-Received: by 2002:a05:620a:4008:b0:775:92ac:a0af with SMTP id h8-20020a05620a400800b0077592aca0afmr35622644qko.13.1697272689385; Sat, 14 Oct 2023 01:38:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697272689; cv=pass; d=google.com; s=arc-20160816; b=DCXqDTYxYtPCmDlyv0WBlhp/sSiEKALGRPtAjEZbEKidagNomJ03ttGyRjqNHvDYM1 wWe0VVGvwzHIA2fi1Li09TaRk/mEv4HioScUsDWNxkeFlE6fNPVx34vW8qA9w5eERGlw w7w2D2DNVNVULPkQckzT7VNkxuWUw3O6uMfDc6wHHX/mfAggXNus+OQz+hjL+unPNz8J /fdsuEOqcA4B67mDEzICSWF6yA53nDFB57tnE6JaALK4KRNd85AlRCth9b45bIa9LFg8 kKDPw8Hl2N8dKhWrqH+3FbuBKzwOw83NwSqt/ZiQJXLvzGwtYEpSvGzD64UIggKtOc4D 3E+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:arc-filter:delivered-to; bh=gTWpuqWCGi46qnN8AA2CB41ibMCH0+q6mH2D76HNgeM=; fh=Q+ZPQdyJDzJx4BfovHNTR1lP4msTSfN6TDra8V1lyf8=; b=psvZXWJG5NbPbvYTnvYbq2axdLzs/veuMVQrcNhZ4wCZXAgW3UCfQbi/PB0KQgvnlG E3Lxc7R9lHgtzFt98m96v3Ek4PBUfOjt+r4mDmhH69xEvEi7UVEtSp/ITkRDqNP9qZFo H1U5VmOzu9Yr9ERA5cNJ5LSj5Y5n6+82pI89TWXk5mP408+5X6QV7H4X2qsSKxab89qw oHGAnZhgrMA5Cdy9Zj0jMLiyu1wZgHbpzLAFoIU68JnfrdQXn/l4ZBFaanHK8H6UhgFM ZBGJ3Yh4yTutUYXn2oUyjI6XskPK97hW4u5R7ebIaDfAfRJO5zcNdLlOJTzA5fsJbstH HIlQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@irq.a4lg.com header.s=2017s01 header.b="QczMuL9/"; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=irq.a4lg.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay6-20020a05620a178600b00775808a3365si2480734qkb.0.2023.10.14.01.38.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 01:38:09 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@irq.a4lg.com header.s=2017s01 header.b="QczMuL9/"; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=irq.a4lg.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2972D385DC09 for ; Sat, 14 Oct 2023 08:38:09 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 462A53857728 for ; Sat, 14 Oct 2023 08:38:00 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 462A53857728 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=153.120.152.154 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697272683; cv=none; b=E3JZScewlWqJ/4SM6XGc6f04uJXpBl1f92LlCxE7MzJ6eexRwtU1Dr7mQE4Rhh67tzQBA4YNymMWmcXny2PqBzsORCntg9klavkJzgbjoeIZvjfrRkpbffuyH9DMZnI3ONUztDMEdqsqYC4BffijIfy7gcPPlOg1gxWyUNVutys= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697272683; c=relaxed/simple; bh=Ku9zPG30ITi1aSMlduhUc882YQ35IlJK4PIeGcc8Xpw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=FThvrfzJTNxJmuJxrvy4xFv6pnmmdyTGlurl/Qp9AKYtLaFhoa8TZzDwh52ZUclQ7LVFxRBVCIwnK4IdwfjZtfRcwToTTqkT0h5NF0YAXpbeKXoXA7bieCKik8G4BvsL0QFT0ncMROxLuXxji8uTjwf+5zIS4VPs49wZoAAIXog= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 462A53857728 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id D5A2C300089; Sat, 14 Oct 2023 08:37:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1697272677; bh=gTWpuqWCGi46qnN8AA2CB41ibMCH0+q6mH2D76HNgeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Mime-Version:Content-Transfer-Encoding; b=QczMuL9/MhOj9Kc27E/rMGzZvxTq9WvEZiKcF5bcgywTTpA/ATwrAJ+a/QqyQ0UbM RoKVO4rXK9lTH7xBAN+gSXpa24Fkpl6R+7q+E5mkYRfXihjQ2Gq4thl7KfQ1aAf8u8 NY/r6a3IBDKm616QVsI/SS+GbAtUYdlgD/DzRY1g= From: Tsukasa OI To: Tsukasa OI , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu , Kito Cheng Cc: binutils@sourceware.org Subject: [PATCH 1/1] RISC-V: Improve handling of mapping symbols with dot suffix Date: Sat, 14 Oct 2023 08:37:37 +0000 Message-ID: In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_MANYTO, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779719394324692159 X-GMAIL-MSGID: 1779719407709735428 From: Tsukasa OI This commit makes minor improvements to mapping symbols (executable) handling with a dot suffix. 1. Use size_t instead of int 2. Allocate minimum size for the architectural string buffer. 3. memcpy instead of strncpy because we know the exact size to copy. 4. Minor variable naming changes. opcodes/ChangeLog: * riscv-dis.c (riscv_get_map_state): Minor improvements to handling of executable mapping symbols with dot suffix. --- opcodes/riscv-dis.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 216916e9426d..18547d81c20d 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -875,12 +875,12 @@ riscv_get_map_state (int n, char *suffix = strchr (name, '.'); if (suffix) { - int suffix_index = (int)(suffix - name); - char *name_substr = xmalloc (suffix_index + 1); - strncpy (name_substr, name, suffix_index); - name_substr[suffix_index] = '\0'; - riscv_parse_subset (&riscv_rps_dis, name_substr + 2); - free (name_substr); + size_t arch_len = (size_t) (suffix - name) - 2; + char *arch = xmalloc (arch_len + 1); + memcpy (arch, name + 2, arch_len); + arch[arch_len] = '\0'; + riscv_parse_subset (&riscv_rps_dis, arch); + free (arch); } else riscv_parse_subset (&riscv_rps_dis, name + 2);