Skip to content

Commit b516c53

Browse files
committed
Fix segfault in at-root cssize edge-case
1 parent 0dea5f2 commit b516c53

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)
@@ -820,13 +820,15 @@ namespace Sass {
820820

821821
void Inspect::operator()(At_Root_Query_Ptr ae)
822822
{
823-
append_string("(");
824-
ae->feature()->perform(this);
825-
if (ae->value()) {
826-
append_colon_separator();
827-
ae->value()->perform(this);
823+
if (ae->feature()) {
824+
append_string("(");
825+
ae->feature()->perform(this);
826+
if (ae->value()) {
827+
append_colon_separator();
828+
ae->value()->perform(this);
829+
}
830+
append_string(")");
828831
}
829-
append_string(")");
830832
}
831833

832834
void Inspect::operator()(Function_Ptr f)

0 commit comments

Comments
 (0)