Skip to content

Commit

Permalink
fix(rs): fix the bug caused by incorrect allocation size of the covar…
Browse files Browse the repository at this point in the history
…iance matrix
  • Loading branch information
Water-Melon committed Apr 25, 2024
1 parent c1268c4 commit 6698d93
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mln_rs.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ MLN_FUNC(static, mln_rs_matrix_t *, mln_rs_matrix_co_inverse_matrix, \
mln_rs_matrix_t *matrix, *inverse;
mln_u8ptr_t p, *pend, data;

if ((data = (mln_u8ptr_t)malloc((n + k) * len)) == NULL) {
if ((data = (mln_u8ptr_t)malloc((n + k) * n)) == NULL) {
errno = ENOMEM;
return NULL;
}
Expand Down
38 changes: 38 additions & 0 deletions t/rs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>
#include <assert.h>
#include "mln_rs.h"

#define COL 10
#define ROW 10
#define K 2

int main(int argc, char *argv[])
{
int i, j;
mln_rs_result_t *res, *dres;
uint8_t origin[COL * ROW] = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
uint8_t *err[ROW + K] = {0};

assert((res = mln_rs_encode(origin, COL, ROW, K)) != NULL);

printf("res->num=%ld, res->len=%ld\n", res->num, res->len);

for (i = 0; i < mln_rs_result_get_num(res); ++i) {
err[i] = mln_rs_result_get_data_by_index(res, i);
}
err[0] = NULL;
err[1] = NULL;

assert((dres = mln_rs_decode(err,COL, ROW, K)) != NULL);

for (i = 0; i < mln_rs_result_get_num(dres); ++i) {
for (j = 0; j < COL; ++j) {
printf("%c", mln_rs_result_get_data_by_index(dres, i)[j]);
}
printf("\n");
}

mln_rs_result_free(res);
mln_rs_result_free(dres);
return 0;
}

0 comments on commit 6698d93

Please sign in to comment.