From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68544 invoked by alias); 1 Sep 2016 11:52:39 -0000 Mailing-List: contact cygwin-apps-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-apps-cvs-owner@sourceware.org Received: (qmail 68520 invoked by uid 9078); 1 Sep 2016 11:52:39 -0000 Date: Thu, 01 Sep 2016 11:52:00 -0000 Message-ID: <20160901115239.68494.qmail@sourceware.org> From: corinna@sourceware.org To: cygwin-apps-cvs@sourceware.org Subject: [setup - the official Cygwin setup program used to install Cygwin and keep it up to date] branch master, updated. release_2.874-23-gd396ed1 X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 4f0fb3e4b44b79600e27136d5bbf4607a3fd45fa X-Git-Newrev: d396ed1058cc89878344a6a1c7097b2cbe88274e X-SW-Source: 2016-q3/txt/msg00017.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=d396ed1058cc89878344a6a1c7097b2cbe88274e commit d396ed1058cc89878344a6a1c7097b2cbe88274e Author: Corinna Vinschen Date: Thu Sep 1 13:52:33 2016 +0200 Fix scope problem when using the return value of get_root_dir() Let get_root_dir return a reference instead of a temporary std::string object. In directory_is_absolute() and directory_is_rootdir(), use std::string methods rather than falling back to plain C techniques. Signed-off-by: Corinna Vinschen Diff: --- mount.cc | 6 ++++-- mount.h | 2 +- root.cc | 22 ++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/mount.cc b/mount.cc index d4c869b..e9c39e2 100644 --- a/mount.cc +++ b/mount.cc @@ -382,10 +382,12 @@ set_root_dir (const std::string val) read_mounts (val); } -const std::string +static std::string empty; + +const std::string & get_root_dir () { - return root_here ? root_here->native : std::string(); + return root_here ? root_here->native : empty; } /* Return non-zero if PATH1 is a prefix of PATH2. diff --git a/mount.h b/mount.h index bc004c3..a7d7e39 100644 --- a/mount.h +++ b/mount.h @@ -33,6 +33,6 @@ mode consistent with the standard Cygwin mounts. */ std::string cygpath (const std::string&); void set_root_dir (const std::string); -const std::string get_root_dir (); +const std::string &get_root_dir (); #endif /* SETUP_MOUNT_H */ diff --git a/root.cc b/root.cc index edf7a91..ec2588a 100644 --- a/root.cc +++ b/root.cc @@ -123,22 +123,24 @@ browse (HWND h) static int directory_is_absolute () { - - const char *r = get_root_dir ().c_str(); - if (isalpha (r[0]) && r[1] == ':' && (r[2] == '\\' || r[2] == '/')) - { - return 1; - } + const std::string &r = get_root_dir (); + if (isalpha (r[0]) && r[1] == ':' && isdirsep (r[2])) + return 1; return 0; } static int directory_is_rootdir () { - - for (const char *c = get_root_dir().c_str(); *c; c++) - if (isdirsep (c[0]) && c[1] && !isdirsep (c[1])) - return 0; + const std::string &r = get_root_dir (); + size_t pos = r.find_first_of ("/\\"); + if (pos != std::string::npos) + { + while (isdirsep (r[++pos])) + ; + if (r[pos]) + return 0; + } return 1; }