Skip to content

Commit 6f8eb39

Browse files
mgreterxzyfer
authored andcommitted
Fix segfault in at-root cssize edge-case
1 parent b5fb4b5 commit 6f8eb39

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/cssize.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ namespace Sass {
2323

2424
Block_Ptr Cssize::operator()(Block_Ptr b)
2525
{
26-
Block_Ptr bb = SASS_MEMORY_NEW(Block, b->pstate(), b->length(), b->is_root());
26+
Block_Obj bb = SASS_MEMORY_NEW(Block, b->pstate(), b->length(), b->is_root());
2727
// bb->tabs(b->tabs());
2828
block_stack.push_back(bb);
2929
append_block(b, bb);
3030
block_stack.pop_back();
31-
return bb;
31+
return bb.detach();
3232
}
3333

3434
Statement_Ptr Cssize::operator()(Trace_Ptr t)
@@ -259,7 +259,7 @@ namespace Sass {
259259
tmp |= m->exclude_node(s);
260260
}
261261

262-
if (!tmp)
262+
if (!tmp && m->block())
263263
{
264264
Block_Ptr bb = operator()(m->block());
265265
for (size_t i = 0, L = bb->length(); i < L; ++i) {
@@ -302,14 +302,17 @@ namespace Sass {
302302

303303
Statement_Ptr Cssize::bubble(At_Root_Block_Ptr m)
304304
{
305+
if (!m || !m->block()) return NULL;
305306
Block_Ptr bb = SASS_MEMORY_NEW(Block, this->parent()->pstate());
306307
Has_Block_Obj new_rule = Cast<Has_Block>(SASS_MEMORY_COPY(this->parent()));
307-
new_rule->block(bb);
308-
new_rule->tabs(this->parent()->tabs());
309-
new_rule->block()->concat(m->block());
310-
311308
Block_Ptr wrapper_block = SASS_MEMORY_NEW(Block, m->block()->pstate());
312-
wrapper_block->append(new_rule);
309+
if (new_rule) {
310+
new_rule->block(bb);
311+
new_rule->tabs(this->parent()->tabs());
312+
new_rule->block()->concat(m->block());
313+
wrapper_block->append(new_rule);
314+
}
315+
313316
At_Root_Block_Ptr mm = SASS_MEMORY_NEW(At_Root_Block,
314317
m->pstate(),
315318
wrapper_block,

src/inspect.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace Sass {
9090
append_token("@at-root ", at_root_block);
9191
append_mandatory_space();
9292
if(at_root_block->expression()) at_root_block->expression()->perform(this);
93-
at_root_block->block()->perform(this);
93+
if(at_root_block->block()) at_root_block->block()->perform(this);
9494
}
9595

9696
void Inspect::operator()(Directive_Ptr at_rule)
@@ -798,13 +798,15 @@ namespace Sass {
798798

799799
void Inspect::operator()(At_Root_Query_Ptr ae)
800800
{
801-
append_string("(");
802-
ae->feature()->perform(this);
803-
if (ae->value()) {
804-
append_colon_separator();
805-
ae->value()->perform(this);
801+
if (ae->feature()) {
802+
append_string("(");
803+
ae->feature()->perform(this);
804+
if (ae->value()) {
805+
append_colon_separator();
806+
ae->value()->perform(this);
807+
}
808+
append_string(")");
806809
}
807-
append_string(")");
808810
}
809811

810812
void Inspect::operator()(Null_Ptr n)

0 commit comments

Comments
 (0)