From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 5C7D33858D1E for ; Sat, 19 Feb 2022 19:51:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C7D33858D1E Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-73VSlyiiMlSoe1OFgUsrmQ-1; Sat, 19 Feb 2022 14:51:48 -0500 X-MC-Unique: 73VSlyiiMlSoe1OFgUsrmQ-1 Received: by mail-wr1-f72.google.com with SMTP id s5-20020adfbc05000000b001e7af4f2231so4989192wrg.3 for ; Sat, 19 Feb 2022 11:51:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O0kzwyvftwu6Qgl+yHUfQnEI7BZnjWpGyvutVjXe4QU=; b=e4mk79Xs/tCe1Hv+MZBqRbe4Q0FnGeTZmVz4a99//6aTSW4peml2JS5IGTtK5N0Hnt mYkl/0MiC9/Z4fXkXzjQktDgzIC6MPBIJgrtC/43qtF3JT/f++FspYYz5vVo+CAwtfCK 7iGaxOPVkx0v7rfdpzj4WtlltYBvINhCmyuXperlE7PXCdj4aNfzvpzqJ2TPiQod3MIb eLprs1oBVQGInta3uywMisTly+OOWMJgP4TO3JkFPWfdfQsb0ocanCRngpN8ALz/rDYF 5FJFTSynK7HT/5rE+Ty2URTn+UZYi3VoiO+4Uoh0iaLGpeoaQR6DyOut8MhZwDg9C8mK olQQ== X-Gm-Message-State: AOAM532MuG5u77U8C7Jg1iyuNkoruvg9s4hxXr0e2WhI3NwmbG66rGec yKd/+IjdMgMuyhtTgJNXEImTyvMHt/QnIKhL5aI3wOSM7LVfvjOerMorgxQYbxaD6P86BSQJv0e B9VCCGOPnBykNEm2V72rnLJZetVkcIZxFmCDCmTr5bI9D+o7fik0d8vgowMwH+3npoPyIZgEAEA == X-Received: by 2002:a1c:43c3:0:b0:37b:c663:156c with SMTP id q186-20020a1c43c3000000b0037bc663156cmr12039036wma.140.1645300307208; Sat, 19 Feb 2022 11:51:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6QElGggvRQhLK4SaRQD57y+AMs/VMf/xCCErv97Y2JiZCoZsRB+xtHfE7pogeCPizOa+GdA== X-Received: by 2002:a1c:43c3:0:b0:37b:c663:156c with SMTP id q186-20020a1c43c3000000b0037bc663156cmr12039020wma.140.1645300306847; Sat, 19 Feb 2022 11:51:46 -0800 (PST) Received: from localhost (host86-134-151-224.range86-134.btcentralplus.com. [86.134.151.224]) by smtp.gmail.com with ESMTPSA id c8sm3615306wmq.34.2022.02.19.11.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Feb 2022 11:51:46 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb: make use of std::string in dbxread.c Date: Sat, 19 Feb 2022 19:51:40 +0000 Message-Id: <854b644e7c6943d0668aee665203265557156a15.1645300222.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 19 Feb 2022 19:51:51 -0000 While taking a look through dbxread.c I spotted a couple of places where making use of std::string would remove the need for manual memory allocation and memcpy. There should be no user visible changes after this commit. --- gdb/dbxread.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/gdb/dbxread.c b/gdb/dbxread.c index 911d518b7e9..ddda5df4ee1 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -1603,13 +1603,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, case 'f': if (! pst) { - int name_len = p - namestring; - char *name = (char *) xmalloc (name_len + 1); - - memcpy (name, namestring, name_len); - name[name_len] = '\0'; - function_outside_compilation_unit_complaint (name); - xfree (name); + std::string name (namestring, (p - namestring)); + function_outside_compilation_unit_complaint (name.c_str ()); } /* Kludges for ELF/STABS with Sun ACC. */ last_function_name = namestring; @@ -1663,13 +1658,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, case 'F': if (! pst) { - int name_len = p - namestring; - char *name = (char *) xmalloc (name_len + 1); - - memcpy (name, namestring, name_len); - name[name_len] = '\0'; - function_outside_compilation_unit_complaint (name); - xfree (name); + std::string name (namestring, (p - namestring)); + function_outside_compilation_unit_complaint (name.c_str ()); } /* Kludges for ELF/STABS with Sun ACC. */ last_function_name = namestring; -- 2.25.4