From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qBSLJkyf7F8ACwAAWB0awg (envelope-from ) for ; Wed, 30 Dec 2020 10:39:56 -0500 Received: by simark.ca (Postfix, from userid 112) id 962751F0B8; Wed, 30 Dec 2020 10:39:56 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6CD7D1F075 for ; Wed, 30 Dec 2020 10:39:55 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB905388E806; Wed, 30 Dec 2020 15:39:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB905388E806 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609342792; bh=IBLDg0U8gaCfqs3xNl4yx4b2JpCYLm24t7PditQloAE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=yZOX3SO4gke/f4+jXbWOruYwJgzs0ZfD87quPVZtmecJzsGh3/bd3JYEIych1Lzne 6yntOgFABQmXARFJmYC3FHovg63GJk0iqRWQEz3kGm8fw2IylHcQ8dp2rtSdsdivYS H11zd+MjV/ZE/+K7T6P+ZpTKipgKBUFAOM9IoDDo= Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id A8FD3388CC1B for ; Wed, 30 Dec 2020 15:39:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A8FD3388CC1B Received: by mail-qt1-x82d.google.com with SMTP id z20so11138589qtq.3 for ; Wed, 30 Dec 2020 07:39:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IBLDg0U8gaCfqs3xNl4yx4b2JpCYLm24t7PditQloAE=; b=gjYZDxaVS8KM42kmCZZgamhE0yf5Cqedj86InACpG4ZP/3fBS8D4FBz/+Q2eLRPuT+ S/Ik+9VQ0wPYamn0+kONdH8xkPbSIxlmhw07PxKBehqnMG3+1qXvISrFh8z7zkTB9myv sQcDxgoQ3Y07LrE0azcFjo6ASazSJOhJZ3buk2qwYrRDsHp9x0iibR8Q6tmt7XzFSV/s RrEWwY2YF6VrKDparldNIu0ZRJ/0K3OU0/Wb1K00+iJAsT+wZIqeWMZ8fxqmNJhxPXiv SmxvxKUzdGjIQw2JaVw78oNaAoaLj5abDUnpXuVtFhSwEjuZh9V+q0hSS3mhmcOyJRMG QKuQ== X-Gm-Message-State: AOAM531ewBMYvhuvZ6pvNqYXHoPJ971lpA7ob3GUJ6bWcmaRuIOyK35t M/4dnpfzQrBKmf9HFHJfKd5rTh8SqsPKKw== X-Google-Smtp-Source: ABdhPJygp/jKEWng8slP6k2UIRccwCM/1Z4HXWmchKJZURLmNniysh4IznLcUt6BkBXwh1mpiESdGw== X-Received: by 2002:ac8:4b54:: with SMTP id e20mr52348799qts.236.1609342789099; Wed, 30 Dec 2020 07:39:49 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:370e:c9ba:c4ec:737b:57da]) by smtp.gmail.com with ESMTPSA id f6sm28589336qkh.2.2020.12.30.07.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Dec 2020 07:39:48 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v4 13/25] Convert char array to std::string in linux_find_memory_regions_full Date: Wed, 30 Dec 2020 12:39:04 -0300 Message-Id: <20201230153916.1586725-14-luis.machado@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201230153916.1586725-1-luis.machado@linaro.org> References: <20201230153916.1586725-1-luis.machado@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , From: Luis Machado via Gdb-patches Reply-To: Luis Machado Cc: david.spickett@linaro.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" This is a quick cleanup that removes the use of fixed-length char arrays and uses std::string instead. gdb/ChangeLog: YYYY-MM-DD Luis Machado * linux-tdep.c (linux_find_memory_regions_full): Use std::string instead of char arrays. --- gdb/linux-tdep.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 5ae28d826c..0e119869e9 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1277,8 +1277,6 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, linux_find_memory_region_ftype *func, void *obfd) { - char mapsfilename[100]; - char coredumpfilter_name[100]; pid_t pid; /* Default dump behavior of coredump_filter (0x33), according to Documentation/filesystems/proc.txt from the Linux kernel @@ -1296,10 +1294,12 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, if (use_coredump_filter) { - xsnprintf (coredumpfilter_name, sizeof (coredumpfilter_name), - "/proc/%d/coredump_filter", pid); + std::string core_dump_filter_name + = string_printf ("/proc/%d/coredump_filter", pid); + gdb::unique_xmalloc_ptr coredumpfilterdata - = target_fileio_read_stralloc (NULL, coredumpfilter_name); + = target_fileio_read_stralloc (NULL, core_dump_filter_name.c_str()); + if (coredumpfilterdata != NULL) { unsigned int flags; @@ -1309,14 +1309,16 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, } } - xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/smaps", pid); + std::string maps_filename = string_printf ("/proc/%d/smaps", pid); + gdb::unique_xmalloc_ptr data - = target_fileio_read_stralloc (NULL, mapsfilename); + = target_fileio_read_stralloc (NULL, maps_filename.c_str ()); + if (data == NULL) { /* Older Linux kernels did not support /proc/PID/smaps. */ - xsnprintf (mapsfilename, sizeof mapsfilename, "/proc/%d/maps", pid); - data = target_fileio_read_stralloc (NULL, mapsfilename); + maps_filename = string_printf ("/proc/%d/maps", pid); + data = target_fileio_read_stralloc (NULL, maps_filename.c_str ()); } if (data != NULL) @@ -1376,7 +1378,8 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, if (sscanf (line, "%64s", keyword) != 1) { - warning (_("Error parsing {s,}maps file '%s'"), mapsfilename); + warning (_("Error parsing {s,}maps file '%s'"), + maps_filename.c_str ()); break; } @@ -1397,7 +1400,7 @@ linux_find_memory_regions_full (struct gdbarch *gdbarch, if (sscanf (line, "%*s%lu", &number) != 1) { warning (_("Error parsing {s,}maps file '%s' number"), - mapsfilename); + maps_filename.c_str ()); break; } if (number > 0) -- 2.25.1