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.129.124]) by sourceware.org (Postfix) with ESMTPS id 3B6BB3858D37 for ; Mon, 21 Feb 2022 11:50:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B6BB3858D37 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-57-i7o0Ij6VMZ6_f92-zF5opA-1; Mon, 21 Feb 2022 06:50:57 -0500 X-MC-Unique: i7o0Ij6VMZ6_f92-zF5opA-1 Received: by mail-wm1-f71.google.com with SMTP id p24-20020a05600c1d9800b0037be98d03a1so7954444wms.0 for ; Mon, 21 Feb 2022 03:50:57 -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:subject:in-reply-to:references:date :message-id:mime-version; bh=9KQxViRaekRiOdlXW6VSEvYtemLy/loyhwoOP73l0qA=; b=HIDuj4XuydrWPFc8XJ65bnJDuv4iDYKwIQGtFsCzCfkGv52tKzTrFpw7U9RBvSnwNR 73O9pqNSziGAcdoSYRDtFrx710Z+zbJsGQx7UQoNOrbjPJOxuula3tYAn9iiQucgsnGK Z4dURXOJG3ufmFXnYRCnwNP43PhCnUB/LYeXLk6J5YODkRGiXeB4I2ZbbzQwiz+BIllV dAdyEyPxGX+Q92E2dY7SViNDRptRD9+M/o4Oyc1cOrRWDjV1WyUqzDal87DCbK7YQVO7 kTafSFOBEPz3W14C+W+lu0Xcy6SCf4N8iV7BjxFAlBXETUrCfa8oGnTBlNzVcF0h+vGr 4lkg== X-Gm-Message-State: AOAM530yL/NtPmrLfvKxKxNmLDoIgS+CN0Z5lsllMg/01Nw4PIAkU6v7 JQ7KydjtUQ3hPqiLedITboekqz/MFXfGOhROGDADAG2BMQiLJQDyYMp9pzOL8v2iPmu35LmJq64 beoNDuvIBUDQsZsDe6hEmxQ== X-Received: by 2002:a05:600c:2e0c:b0:37c:3615:c52 with SMTP id o12-20020a05600c2e0c00b0037c36150c52mr17018858wmf.43.1645444256120; Mon, 21 Feb 2022 03:50:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmRBmUHwmfVdP5GtYWLa271rluOZjM67tW4R3tkKShIrAxghNGKjHPl0IPkpeH1vLx00MrGw== X-Received: by 2002:a05:600c:2e0c:b0:37c:3615:c52 with SMTP id o12-20020a05600c2e0c00b0037c36150c52mr17018847wmf.43.1645444255907; Mon, 21 Feb 2022 03:50:55 -0800 (PST) Received: from localhost (host86-169-131-29.range86-169.btcentralplus.com. [86.169.131.29]) by smtp.gmail.com with ESMTPSA id m12-20020a7bce0c000000b0037bed2a6fbfsm7413869wmc.37.2022.02.21.03.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:50:55 -0800 (PST) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] gdb: make use of std::string in dbxread.c In-Reply-To: References: <854b644e7c6943d0668aee665203265557156a15.1645300222.git.aburgess@redhat.com> Date: Mon, 21 Feb 2022 11:50:54 +0000 Message-ID: <87mtikcuap.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: Mon, 21 Feb 2022 11:51:00 -0000 Simon Marchi via Gdb-patches writes: > On 2022-02-19 14:51, Andrew Burgess via Gdb-patches wrote: >> 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. > > LGTM. > > It's not really related, but there is the exact same code that could be > changed in the exact same way in xcoffread.c, it would be nice to change > it as well. Thanks, I pushed the patch below that also fixes xcoffread.c. Andrew --- commit 9c6c44713f31f7b27bfe6921de378fa69127a048 Author: Andrew Burgess Date: Sat Feb 19 13:08:32 2022 +0000 gdb: make use of std::string in dbxread.c and xcoffread.c 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. During review Simon pointed out that the same code exists in xcoffread.c, so I've applied the same fix there too. There should be no user visible changes after this commit. 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; diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index d3e9ade72cb..f6db7f9ff7e 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -2734,13 +2734,8 @@ scan_xcoff_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 ()); } pst->add_psymbol (gdb::string_view (namestring, p - namestring), @@ -2758,13 +2753,8 @@ scan_xcoff_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 ()); } /* We need only the minimal symbols for these