Skip to content

Commit

Permalink
fix the loops
Browse files Browse the repository at this point in the history
  • Loading branch information
exarkun committed Sep 20, 2023
1 parent 6bc68a3 commit c506244
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions zfec/fec.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ fec_encode(const fec_t* code, const gf*restrict const*restrict const src, gf*res
*/
void
build_decode_matrix_into_space(const fec_t*restrict const code, const unsigned*const restrict index, const unsigned k, gf*restrict const matrix) {
unsigned char i;
unsigned short i;
gf* p;
for (i=0, p=matrix; i < k; i++, p += k) {
if (index[i] < k) {
Expand All @@ -527,9 +527,22 @@ build_decode_matrix_into_space(const fec_t*restrict const code, const unsigned*c
void
fec_decode(const fec_t* code, const gf*restrict const*restrict const inpkts, gf*restrict const*restrict const outpkts, const unsigned*restrict const index, size_t sz) {
gf* m_dec = (gf*)alloca(code->k * code->k);

/* char is large enough for outix - it counts the number of primary blocks
we are decoding for return. the most primary blocks we might have to
decode is for k == 128, m == 256. in this case we might be given 128
secondary blocks and have to decode 128 primary blocks. if k decreases
then the number of total blocks we might have to return decreases. if
k increases then the number of secondary blocks that exist decreases so
we will be passed some primary blocks and the number of primary blocks
we have to decode decreases. */
unsigned char outix=0;
unsigned char row=0;
unsigned char col=0;

/* row and col are compared directly to k, which could be 256, so make
them large enough to represent 256.
*/
unsigned short row=0;
unsigned short col=0;
build_decode_matrix_into_space(code, index, code->k, m_dec);

for (row=0; row<code->k; row++) {
Expand Down

0 comments on commit c506244

Please sign in to comment.