mirror of
https://github.com/intel/isa-l.git
synced 2025-10-28 11:31:51 +01:00
erasure_code: various fixes for static code analysis issues
Signed-off-by: Tomasz Kantecki <tomasz.kantecki@intel.com>
This commit is contained in:
committed by
Marcel Cornu
parent
ac2ee91cdb
commit
402bd4f773
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include <assert.h>
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
@@ -112,10 +113,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("erasure_code_base_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);
|
||||
|
||||
if (m > MMAX || k > KMAX || nerrs > (m - k)) {
|
||||
printf(" Input test parameter error\n");
|
||||
return -1;
|
||||
}
|
||||
// check input parameters
|
||||
assert(!(m > MMAX || k > KMAX || nerrs > (m - k)));
|
||||
|
||||
memcpy(src_err_list, err_list, nerrs);
|
||||
memset(src_in_err, 0, TEST_SOURCES);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include <assert.h>
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
@@ -264,8 +265,7 @@ int main(int argc, char *argv[])
|
||||
// Pick a first test
|
||||
m = 9;
|
||||
k = 5;
|
||||
if (m > MMAX || k > KMAX)
|
||||
return -1;
|
||||
assert((m <= MMAX) && (k <= KMAX));
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
|
||||
@@ -142,7 +142,6 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
m = k + p;
|
||||
|
||||
if (nerrs > k) {
|
||||
printf
|
||||
@@ -151,6 +150,21 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (k <= 0) {
|
||||
printf("Number of source buffers (%d) must be > 0\n", k);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (p <= 0) {
|
||||
printf("Number of parity buffers (%d) must be > 0\n", p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nerrs <= 0) {
|
||||
printf("Number of errors (%d) must be > 0\n", nerrs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nerrs > p) {
|
||||
printf
|
||||
("Number of errors (%d) cannot be higher than number of parity buffers (%d)\n",
|
||||
@@ -158,13 +172,15 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
m = k + p;
|
||||
|
||||
if (m > MMAX) {
|
||||
printf("Number of total buffers (data and parity) cannot be higher than %d\n",
|
||||
MMAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
u8 *err_list = malloc(nerrs);
|
||||
u8 *err_list = malloc((size_t)nerrs);
|
||||
if (err_list == NULL) {
|
||||
printf("Error allocating list of array of error indices\n");
|
||||
return -1;
|
||||
@@ -185,7 +201,7 @@ int main(int argc, char *argv[])
|
||||
printf("Testing with %u data buffers and %u parity buffers (num errors = %u, in [ ", k,
|
||||
p, nerrs);
|
||||
for (i = 0; i < nerrs; i++)
|
||||
printf("%d ", err_list[i]);
|
||||
printf("%d ", (int)err_list[i]);
|
||||
|
||||
printf("])\n");
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include <assert.h>
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
@@ -266,10 +267,7 @@ int main(int argc, char *argv[])
|
||||
// Pick a first test
|
||||
m = 9;
|
||||
k = 5;
|
||||
if (m > MMAX || k > KMAX) {
|
||||
re = -1;
|
||||
goto exit;
|
||||
}
|
||||
assert((m <= MMAX) && (k <= KMAX));
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++)
|
||||
|
||||
@@ -179,7 +179,6 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
m = k + p;
|
||||
|
||||
if (nerrs > k) {
|
||||
printf
|
||||
@@ -188,6 +187,16 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (k <= 0) {
|
||||
printf("Number of source buffers (%d) must be > 0\n", k);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (p <= 0) {
|
||||
printf("Number of parity buffers (%d) must be > 0\n", p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nerrs > p) {
|
||||
printf
|
||||
("Number of errors (%d) cannot be higher than number of parity buffers (%d)\n",
|
||||
@@ -195,13 +204,20 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nerrs <= 0) {
|
||||
printf("Number of errors (%d) must be > 0\n", nerrs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
m = k + p;
|
||||
|
||||
if (m > MMAX) {
|
||||
printf("Number of total buffers (data and parity) cannot be higher than %d\n",
|
||||
MMAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
u8 *err_list = malloc(nerrs);
|
||||
u8 *err_list = malloc((size_t)nerrs);
|
||||
if (err_list == NULL) {
|
||||
printf("Error allocating list of array of error indices\n");
|
||||
return -1;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include <assert.h>
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
@@ -290,8 +291,7 @@ int main(int argc, char *argv[])
|
||||
// Pick a first test
|
||||
m = 14;
|
||||
k = 10;
|
||||
if (m > MMAX || k > KMAX)
|
||||
goto exit;
|
||||
assert(!(m > MMAX || k > KMAX));
|
||||
|
||||
// Make random data
|
||||
for (i = 0; i < k; i++) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define ROWS M_MAX
|
||||
#define COLS K_MAX
|
||||
|
||||
static inline int min(int a, int b)
|
||||
static inline uint64_t min(const uint64_t a, const uint64_t b)
|
||||
{
|
||||
if (a <= b)
|
||||
return a;
|
||||
@@ -17,10 +17,11 @@ static inline int min(int a, int b)
|
||||
return b;
|
||||
}
|
||||
|
||||
void gen_sub_matrix(unsigned char *out_matrix, int dim, unsigned char *in_matrix, int rows,
|
||||
int cols, uint64_t row_indicator, uint64_t col_indicator)
|
||||
void gen_sub_matrix(unsigned char *out_matrix, const uint64_t dim, unsigned char *in_matrix,
|
||||
const uint64_t rows, const uint64_t cols, const uint64_t row_indicator,
|
||||
const uint64_t col_indicator)
|
||||
{
|
||||
int i, j, r, s;
|
||||
uint64_t i, j, r, s;
|
||||
|
||||
for (i = 0, r = 0; i < rows; i++) {
|
||||
if (!(row_indicator & ((uint64_t) 1 << i)))
|
||||
@@ -51,23 +52,23 @@ uint64_t next_subset(uint64_t * subset, uint64_t element_count, uint64_t subsize
|
||||
return 0;
|
||||
}
|
||||
|
||||
int are_submatrices_singular(unsigned char *vmatrix, int rows, int cols)
|
||||
int are_submatrices_singular(unsigned char *vmatrix, const uint64_t rows, const uint64_t cols)
|
||||
{
|
||||
unsigned char matrix[COLS * COLS];
|
||||
unsigned char invert_matrix[COLS * COLS];
|
||||
uint64_t row_indicator, col_indicator, subset_init, subsize;
|
||||
uint64_t subsize;
|
||||
|
||||
/* Check all square subsize x subsize submatrices of the rows x cols
|
||||
* vmatrix for singularity*/
|
||||
for (subsize = 1; subsize <= min(rows, cols); subsize++) {
|
||||
subset_init = (1 << subsize) - 1;
|
||||
col_indicator = subset_init;
|
||||
const uint64_t subset_init = (1ULL << subsize) - 1ULL;
|
||||
uint64_t col_indicator = subset_init;
|
||||
do {
|
||||
row_indicator = subset_init;
|
||||
uint64_t row_indicator = subset_init;
|
||||
do {
|
||||
gen_sub_matrix(matrix, subsize, vmatrix, rows,
|
||||
cols, row_indicator, col_indicator);
|
||||
if (gf_invert_matrix(matrix, invert_matrix, subsize))
|
||||
if (gf_invert_matrix(matrix, invert_matrix, (int)subsize))
|
||||
return 1;
|
||||
|
||||
} while (next_subset(&row_indicator, rows, subsize) == 0);
|
||||
@@ -80,7 +81,7 @@ int are_submatrices_singular(unsigned char *vmatrix, int rows, int cols)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
unsigned char vmatrix[(ROWS + COLS) * COLS];
|
||||
int rows, cols;
|
||||
uint64_t rows, cols;
|
||||
|
||||
if (K_MAX > MAX_CHECK) {
|
||||
printf("K_MAX too large for this test\n");
|
||||
@@ -108,7 +109,7 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
}
|
||||
printf(" k = %2d, m <= %2d \n", cols, rows + cols - 1);
|
||||
printf(" k = %2u, m <= %2u \n", (unsigned)cols, (unsigned)(rows + cols - 1));
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h> // for memset, memcmp
|
||||
#include <assert.h>
|
||||
#include "erasure_code.h"
|
||||
#include "test.h"
|
||||
|
||||
@@ -134,8 +135,7 @@ int main(int argc, char *argv[])
|
||||
// Pick a first test
|
||||
m = 9;
|
||||
k = 5;
|
||||
if (m > MMAX || k > KMAX)
|
||||
return -1;
|
||||
assert(!(m > MMAX || k > KMAX));
|
||||
|
||||
gf_gen_cauchy1_matrix(a, m, k);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user