public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
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
Date: Thu, 01 Sep 2016 11:52:00 -0000	[thread overview]
Message-ID: <20160901115239.68494.qmail@sourceware.org> (raw)




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=d396ed1058cc89878344a6a1c7097b2cbe88274e

commit d396ed1058cc89878344a6a1c7097b2cbe88274e
Author: Corinna Vinschen <corinna@vinschen.de>
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 <corinna@vinschen.de>


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;
 }
 


                 reply	other threads:[~2016-09-01 11:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160901115239.68494.qmail@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-apps-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).