public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
* [setup - the official Cygwin setup program used to install Cygwin and keep it up to date] branch master, updated. release_2.874-23-gd396ed1
@ 2016-09-01 11:52 corinna
0 siblings, 0 replies; only message in thread
From: corinna @ 2016-09-01 11:52 UTC (permalink / raw)
To: cygwin-apps-cvs
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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-09-01 11:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-01 11:52 [setup - the official Cygwin setup program used to install Cygwin and keep it up to date] branch master, updated. release_2.874-23-gd396ed1 corinna
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).