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