Skip to content

Commit

Permalink
Use variable length arrays for data and coding pointer arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed Aug 29, 2018
1 parent 706bdcf commit 9f86bca
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions c_src/erasure.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ encode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
int extra_bytes = input.size % k;

char *shards = calloc(k+m, blockspacing);
char **data_ptrs = calloc(k, sizeof(char*));
char **coding_ptrs = calloc(m, sizeof(char*));
char *data_ptrs[k];
char *coding_ptrs[m];

unsigned char *p = input.data;
for (int i = 0; i < k+m; i++) {
Expand Down Expand Up @@ -106,8 +106,6 @@ encode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
), list);
}
free(shards);
free(data_ptrs);
free(coding_ptrs);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), list);
}

Expand Down Expand Up @@ -135,8 +133,8 @@ decode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
}

char *shards = NULL;
char **data_ptrs = calloc(k, sizeof(char*));
char **coding_ptrs = calloc(m, sizeof(char*));
char *data_ptrs[k];
char *coding_ptrs[m];

int *erasures = NULL;

Expand Down Expand Up @@ -268,8 +266,6 @@ decode(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
if (shards != NULL) {
free(shards);
}
free(coding_ptrs);
free(data_ptrs);
if (erasures != NULL) {
free(erasures);
}
Expand Down

0 comments on commit 9f86bca

Please sign in to comment.