From 6c18db1ae142c173cceaa32491b4da49c96e667e 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 0b6248d4b6..ed8db07b61 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -1085,18 +1085,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_;