Skip to content

Commit

Permalink
fix(DmStyle): infinite loop if no pattern matches
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed May 3, 2024
1 parent dfb4301 commit 86f168f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Style.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ DmPattern* DmStyle_getRandomPattern(DmStyle* slf, uint32_t groove, DmCommandType
// but I couldn't find it.

int64_t index = Dm_rand() % (uint32_t) slf->patterns.length;
bool found_one = false;
do {
for (size_t i = 0; i < slf->patterns.length; ++i) {
DmPattern* pttn = &slf->patterns.data[i];
Expand All @@ -136,8 +137,9 @@ DmPattern* DmStyle_getRandomPattern(DmStyle* slf, uint32_t groove, DmCommandType
}

index -= 1;
found_one = true;
}
} while (index >= 0);
} while (found_one);

return NULL;
}
Expand Down

0 comments on commit 86f168f

Please sign in to comment.