From 320e849d17597aef40b9e3e62f79319f13f97e45 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 16 May 2018 16:05:05 +0300 Subject: Fix uncaught invalid_path exception --- build2/algorithm.cxx | 4 ++-- build2/b.cxx | 2 +- build2/cc/common.cxx | 5 ++++- build2/parser.cxx | 30 +++++++++++++++++++----------- build2/scope.cxx | 12 ++++++++++-- build2/scope.hxx | 2 +- 6 files changed, 37 insertions(+), 18 deletions(-) diff --git a/build2/algorithm.cxx b/build2/algorithm.cxx index f695c74..ba9f5bc 100644 --- a/build2/algorithm.cxx +++ b/build2/algorithm.cxx @@ -50,7 +50,7 @@ namespace build2 assert (phase == run_phase::match); optional ext; - const target_type* tt (s.find_target_type (n, ext)); + const target_type* tt (s.find_target_type (n, ext, location ())); if (tt == nullptr) fail << "unknown target type " << n.type << " in name " << n; @@ -78,7 +78,7 @@ namespace build2 name n (cn); optional ext; - const target_type* tt (s.find_target_type (n, ext)); + const target_type* tt (s.find_target_type (n, ext, location ())); // For now we treat an unknown target type as an unknown target. Seems // logical. diff --git a/build2/b.cxx b/build2/b.cxx index 70fb470..89929b1 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -1263,7 +1263,7 @@ main (int argc, char* argv[]) // Find the target type and extract the extension. // optional e; - const target_type* ti (bs.find_target_type (tn, e)); + const target_type* ti (bs.find_target_type (tn, e, l)); if (ti == nullptr) fail (l) << "unknown target type " << tn.type; diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx index e4dbfe8..c32d83e 100644 --- a/build2/cc/common.cxx +++ b/build2/cc/common.cxx @@ -429,7 +429,10 @@ namespace build2 // This is import. // optional ext; - const target_type* tt (s.find_target_type (n, ext)); // Changes name. + + // Changes name. + // + const target_type* tt (s.find_target_type (n, ext, location ())); if (tt == nullptr) fail << "unknown target type '" << n.type << "' in library " << n; diff --git a/build2/parser.cxx b/build2/parser.cxx index 96465f6..bbce5e5 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -150,7 +150,7 @@ namespace build2 const location& loc) { optional e; - const target_type* ti (p.scope_->find_target_type (n, e)); + const target_type* ti (p.scope_->find_target_type (n, e, loc)); if (ti == nullptr) p.fail (loc) << "unknown target type " << n.type; @@ -735,7 +735,7 @@ namespace build2 for (auto& pn: pns) { optional e; - const target_type* ti (scope_->find_target_type (pn, e)); + const target_type* ti (scope_->find_target_type (pn, e, ploc)); if (ti == nullptr) fail (ploc) << "unknown target type " << pn.type; @@ -3104,19 +3104,27 @@ namespace build2 << " pattern"; } - if (s == '+') + try { - if (p) - include_pattern (move (v), a); + if (s == '+') + { + if (p) + include_pattern (move (v), a); + else + include_match (move (v), a); + } else - include_match (move (v), a); + { + if (p) + exclude_pattern (move (v)); + else + exclude_match (v); + } } - else + catch (const invalid_path& e) { - if (p) - exclude_pattern (move (v)); - else - exclude_match (v); + fail (l) << "invalid path '" << e.path << "' in " << what + << " pattern"; } } diff --git a/build2/scope.cxx b/build2/scope.cxx index a15eeba..e5762f1 100644 --- a/build2/scope.cxx +++ b/build2/scope.cxx @@ -569,7 +569,7 @@ namespace build2 static const string file_tt ("file"); const target_type* scope:: - find_target_type (name& n, optional& ext) const + find_target_type (name& n, optional& ext, const location& loc) const { ext = nullopt; @@ -622,7 +622,15 @@ namespace build2 if (i != string::npos) { - n.dir /= dir_path (v, i != 0 ? i : 1); // Special case: "/". + try + { + n.dir /= dir_path (v, i != 0 ? i : 1); // Special case: "/". + } + catch (const invalid_path& e) + { + fail (loc) << "invalid path '" << e.path << "'"; + } + v = string (v, i + 1, string::npos); } diff --git a/build2/scope.hxx b/build2/scope.hxx index 0bfd76e..527ff86 100644 --- a/build2/scope.hxx +++ b/build2/scope.hxx @@ -218,7 +218,7 @@ namespace build2 // necessarily normalized). Return NULL if not found. // const target_type* - find_target_type (name&, optional& ext) const; + find_target_type (name&, optional& ext, const location&) const; // Dynamically derive a new target type from an existing one. Return the // reference to the target type and an indicator of whether it was -- cgit v1.1