From ce4b3b115957575c2055291c54fc6452817dab87 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 13 Sep 2022 16:07:41 +0200 Subject: Fix bug in handling of disabled recipes in ad hoc pattern rules --- libbuild2/parser.cxx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/libbuild2/parser.cxx b/libbuild2/parser.cxx index 7e48ad8..03b912d 100644 --- a/libbuild2/parser.cxx +++ b/libbuild2/parser.cxx @@ -1253,8 +1253,13 @@ namespace build2 for (shared_ptr& pr: recipes) { - pr->pattern = &rp; // Connect recipe to pattern. - rp.rules.push_back (move (pr)); + // Can be NULL if the recipe is disabled with a condition. + // + if (pr != nullptr) + { + pr->pattern = &rp; // Connect recipe to pattern. + rp.rules.push_back (move (pr)); + } } // Register this adhoc rule for all its actions. @@ -1766,7 +1771,15 @@ namespace build2 t = start; tt = t.type; for (size_t i (0); tt == type::percent || tt == type::multi_lcbrace; ++i) { - recipes.push_back (nullptr); // For missing else/default (see below). + // For missing else/default (see below). + // + // Note that it may remain NULL if we have, say, an if-condition that + // evaluates to false and no else. While it may be tempting to get rid + // of such "holes", it's not easy due to the replay semantics (see the + // target_ != nullptr block below). So we expect the caller to be + // prepared to handle this. + // + recipes.push_back (nullptr); attributes as; buildspec bs; -- cgit v1.1