aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-07-24 19:03:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-07-24 19:03:30 +0200
commitcc75e759479c72ba3ae1c7465ea1e2eeca09f18e (patch)
tree81870e94a683f43854b620242803a185cb322ef3 /odb
parent83a56cf2b87580cbd9d8ca0290f3f74d2dfa0492 (diff)
Fix bug in passing empty option values via plugin command line
Diffstat (limited to 'odb')
-rw-r--r--odb/odb.cxx32
-rw-r--r--odb/plugin.cxx2
2 files changed, 21 insertions, 13 deletions
diff --git a/odb/odb.cxx b/odb/odb.cxx
index af60299..cea2e72 100644
--- a/odb/odb.cxx
+++ b/odb/odb.cxx
@@ -114,6 +114,9 @@ wait_process (process_info, char const* name);
//
//
static string
+encode_plugin_flag (string const& k);
+
+static string
encode_plugin_option (string const& k, string const& v);
// Extract header search paths from GCC's -v output. May throw the
@@ -695,8 +698,7 @@ main (int argc, char* argv[])
cli::options const& desc (options::description ());
for (size_t i (0); i < end; ++i)
{
- string k, v;
- string a (plugin_args[i]);
+ string k, a (plugin_args[i]);
// Ignore certain options.
//
@@ -727,10 +729,12 @@ main (int argc, char* argv[])
else
k = string (a, 1); // short format
- // If there are more arguments then we may have a value.
- //
- if (!it->flag ())
+ if (it->flag ())
+ db_args.push_back (encode_plugin_flag (k));
+ else
{
+ // If there are more arguments then we may have a value.
+ //
if (i + 1 == end)
{
e << argv[0] << ": ice: expected argument for '" << a << "'"
@@ -738,10 +742,8 @@ main (int argc, char* argv[])
return 1;
}
- v = plugin_args[++i];
+ db_args.push_back (encode_plugin_option (k, plugin_args[++i]));
}
-
- db_args.push_back (encode_plugin_option (k, v));
}
// Reserve space for and remember the position of the svc-file
@@ -1143,19 +1145,25 @@ main (int argc, char* argv[])
}
}
+static inline string
+encode_plugin_flag (string const& k)
+{
+ return "-fplugin-arg-odb-" + k;
+}
+
static string
encode_plugin_option (string const& k, string const& cv)
{
- string o ("-fplugin-arg-odb-"), v (cv);
+ string o ("-fplugin-arg-odb-");
o += k;
+ o += '=';
- if (!v.empty ())
+ if (!cv.empty ())
{
- o += '=';
-
// A value cannot contain '='. Encode it as the backspace
// character.
//
+ string v (cv);
for (size_t i (0); i < v.size (); ++i)
if (v[i] == '=')
v[i] = '\b';
diff --git a/odb/plugin.cxx b/odb/plugin.cxx
index ed7bd14..fbbfe46 100644
--- a/odb/plugin.cxx
+++ b/odb/plugin.cxx
@@ -317,7 +317,7 @@ plugin_init (plugin_name_args* plugin_info, plugin_gcc_version*)
argv_str.push_back (opt);
- if (!v.empty ())
+ if (a.value != 0)
argv_str.push_back (v);
}