From 748f097a7a4fda4c83bc179e522ea6b43a7813ec Mon Sep 17 00:00:00 2001 From: Marcel Greter Date: Tue, 23 Feb 2016 00:57:47 +0100 Subject: [PATCH] Fix segfault with non existing extend and parent selector Cherry-picked from #1925. Fixes #1916 Spec sass/sass-spec#732 --- src/ast.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ast.cpp b/src/ast.cpp index 9d2683f070..55c252ba6f 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -1086,18 +1086,16 @@ namespace Sass { Complex_Selector* Complex_Selector::first() { // declare variables used in loop - Complex_Selector* cur = this->tail_; - const Compound_Selector* head = head_; + Complex_Selector* cur = this; + const Compound_Selector* head; // processing loop while (cur) { // get the head head = cur->head_; - // check for single parent ref - if (head && head->length() == 1) - { - // abort (and return) if it is not a parent selector - if (!dynamic_cast((*head)[0])) break; + // abort (and return) if it is not a parent selector + if (!head || head->length() != 1 || !dynamic_cast((*head)[0])) { + break; } // advance to next cur = cur->tail_;