Skip to content

Commit

Permalink
Merge pull request #3032 from mgreter/bugfix/edge-case-crashes
Browse files Browse the repository at this point in the history
Fix various edge case crashes
  • Loading branch information
mgreter authored Nov 4, 2019
2 parents e1c16e0 + cbf4cb8 commit d911058
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/extender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ namespace Sass {
// ##########################################################################
bool Extender::checkForUnsatisfiedExtends(Extension& unsatisfied) const
{
if (selectors.empty()) return false;
ExtSmplSelSet originals = getSimpleSelectors();
for (auto target : extensions) {
SimpleSelector* key = target.first;
Expand Down
10 changes: 6 additions & 4 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2247,15 +2247,17 @@ namespace Sass {
if (lex < kwd_not >()) { media_query->is_negated(true); lex < css_comments >(false); }
else if (lex < kwd_only >()) { media_query->is_restricted(true); lex < css_comments >(false); }

if (lex < identifier_schema >()) media_query->media_type(parse_identifier_schema());
else if (lex < identifier >()) media_query->media_type(parse_interpolated_chunk(lexed));
if (lex < identifier_schema >()) media_query->media_type(parse_identifier_schema());
else if (lex < identifier >()) media_query->media_type(parse_interpolated_chunk(lexed));
else media_query->append(parse_media_expression());

while (lex_css < kwd_and >()) media_query->append(parse_media_expression());
if (lex < identifier_schema >()) {
String_Schema* schema = SASS_MEMORY_NEW(String_Schema, pstate);
schema->append(media_query->media_type());
schema->append(SASS_MEMORY_NEW(String_Constant, pstate, " "));
if (media_query->media_type()) {
schema->append(media_query->media_type());
schema->append(SASS_MEMORY_NEW(String_Constant, pstate, " "));
}
schema->append(parse_identifier_schema());
media_query->media_type(schema);
}
Expand Down
13 changes: 9 additions & 4 deletions src/permutate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Sass {

size_t L = in.size(), n = 0;

if (L == 0) return {};
// Exit early if any entry is empty
for (size_t i = 0; i < L; i += 1) {
if (in[i].size() == 0) return {};
Expand Down Expand Up @@ -80,12 +81,18 @@ namespace Sass {

size_t L = in.size();
size_t n = in.size() - 1;

if (L == 0) return {};
// Exit early if any entry is empty
for (size_t i = 0; i < L; i += 1) {
if (in[i].size() == 0) return {};
}

size_t* state = new size_t[L];
std::vector< std::vector<T>> out;

// First initialize all states for every permutation group
for (size_t i = 0; i < L; i += 1) {
if (in[i].size() == 0) return {};
state[i] = in[i].size() - 1;
}

Expand All @@ -104,10 +111,8 @@ namespace Sass {
// Current group finished
if (state[n] == 0) {
// Find position of next decrement
while (n > 0 && state[--n] == 0)
{
while (n > 0 && state[--n] == 0) {}

}
// Check for end condition
if (state[n] != 0) {
// Decrease next on the left side
Expand Down

0 comments on commit d911058

Please sign in to comment.