From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id UPYEMlzLEWA2TwAAWB0awg (envelope-from ) for ; Wed, 27 Jan 2021 15:21:48 -0500 Received: by simark.ca (Postfix, from userid 112) id C3CF01EF88; Wed, 27 Jan 2021 15:21:48 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [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 63D4F1EF7A for ; Wed, 27 Jan 2021 15:21:47 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA3C9398B84B; Wed, 27 Jan 2021 20:21:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA3C9398B84B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611778903; bh=eudhUYKsBUTauvpml8v7EtLAPhb+ndmh+Qr3VuD+GEw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=f+Q/UKfG+mtbslRrchsQ7iPWs0so3QTnJq2FSTG9Pgnnqp3JHFDtucYdPxT6Rf9vu g8dzmd6BDLloCzssDsQvM10PbFqbi+8q0p37MsExHufn85xmEDZeQfWqPCH0Oww5ru cJHdHJkawmQ0NRXnKIUJmaoms3DgubKoDNscrqAs= Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id 395DF398B83A for ; Wed, 27 Jan 2021 20:21:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 395DF398B83A Received: by mail-qt1-x835.google.com with SMTP id e17so2440146qto.3 for ; Wed, 27 Jan 2021 12:21:40 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eudhUYKsBUTauvpml8v7EtLAPhb+ndmh+Qr3VuD+GEw=; b=ARyTCvh41Z4LHU6aeMH6WnEYZPmj9OzPx12vitMRI+JqksGLksLPAR4BL0GFwGqqtE KWe1VyInBbsTyL+WuBnaH4789P3D5M5MrcCcaJ5nlvE+TWPw/RsVmWAv77bNL+oRy1Mc iCKGHxyUNF9nEV1PE1upHAVylzX+qqzrWnQEB55s57Xldzql1iPMWZPnhaxXjNusZhh1 doz3UeaKgKx6g5ajolNnAYW45TvaGKtgJZB7m7jtpZqOuLG1pOfQqKnxp5ev2ibfdYyQ 0INZIHJouJ3s2KaUpBpFsWTcP5AxU6OHQJqGVjKehOj+AoIcuzc6OPTVL2sk1xiaYYt8 or6Q== X-Gm-Message-State: AOAM531su0CjoENpbmyFSmOpeaYtq2O/g2/DCm8mSfmQEuk6xIhYjYT2 1Tm/ZxvftS5kAHUEYbT4QpgHXjkjZYvy1A== X-Google-Smtp-Source: ABdhPJyu9Yd2Hhr9qZ++vU198Pbx+z/J4+VICM/1pMM5kf9NEjzQG4agjeePRB3VFO/t5T8oPdFr1Q== X-Received: by 2002:ac8:7257:: with SMTP id l23mr11155290qtp.264.1611778899676; Wed, 27 Jan 2021 12:21:39 -0800 (PST) Received: from localhost.localdomain ([2804:7f0:8284:874d:b82c:87fc:4324:adab]) by smtp.gmail.com with ESMTPSA id b194sm1854531qkc.102.2021.01.27.12.21.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jan 2021 12:21:39 -0800 (PST) To: gdb-patches@sourceware.org Subject: [PATCH v5 13/25] Convert char array to std::string in linux_find_memory_regions_full Date: Wed, 27 Jan 2021 17:21:00 -0300 Message-Id: <20210127202112.2485702-14-luis.machado@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210127202112.2485702-1-luis.machado@linaro.org> References: <20210127202112.2485702-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 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 e9f8e1b613..35e05e12a6 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