Skip to content

Commit

Permalink
Fix too small memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
axelf4 committed Apr 16, 2024
1 parent 864d07c commit d8976c4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions hotfuzz-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ static int calc_cost(struct Str needle, struct Str haystack, bool ignore_case) {
*/
static bool is_match(char *needle, char *haystack, bool ignore_case) {
while (*needle)
if (haystack = ignore_case
? strpbrk(haystack, (char[]) { *needle, toupper_utf8(*needle), '\0' })
: strchr(haystack, *needle))
if ((haystack = ignore_case
? strpbrk(haystack, (char[]) { *needle, toupper_utf8(*needle), '\0' })
: strchr(haystack, *needle)))
++needle, ++haystack; // Skip past matched character
else
return false;
Expand Down Expand Up @@ -281,7 +281,8 @@ int emacs_module_init(struct emacs_runtime *rt) {

long max_workers = sysconf(_SC_NPROCESSORS_ONLN);
struct Data *data;
if (!(data = malloc(max_workers * sizeof *data->threads))) return 1;
if (!(data = malloc(sizeof *data + max_workers * sizeof *data->threads)))
return 1;
*data = (struct Data) { max_workers };

env->funcall(env, env->intern(env, "defalias"), 2, (emacs_value[]) {
Expand Down

0 comments on commit d8976c4

Please sign in to comment.