Fix matrix inverse syntax and make bounded conversions explicit
This commit is contained in:
1 parent
70793605c6
commit
9aa43f68fa
2 files changed
+10
-10
No files matched your search
+4
-4
@@ -47,7 +47,7 @@ static int rs_invert(struct rs_codec *ctx, const uint8_t *const rows[]) {
|
||||
other[j] = tmp;
|
||||
}
|
||||
}
|
||||
uint8_t inverse = ctx->gf_exp[255 - ctx->gf_log[row[col]];
|
||||
uint8_t inverse = ctx->gf_exp[255 - ctx->gf_log[row[col]]];
|
||||
for (unsigned j = col; j < stride; j++) row[j] = rs_multiply(ctx, row[j], inverse);
|
||||
for (unsigned i = 0; i < k; i++) {
|
||||
if (i == col) continue;
|
||||
@@ -101,7 +101,7 @@ int rs_init(struct rs_codec **out, unsigned n, unsigned r, size_t block_size) {
|
||||
}
|
||||
unsigned k = n - r;
|
||||
size_t bytes = sizeof(struct rs_codec) + n * k + 2 * k * k;
|
||||
struct rs_codec *ctx = u_calloc(1, bytes);
|
||||
struct rs_codec *ctx = u_calloc(1, (uint32_t)bytes);
|
||||
if (!ctx) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "reed_solomon: allocation failed n=%u r=%u block_size=%zu bytes=%zu", n, r, block_size, bytes);
|
||||
return RS_ERR_MEMORY;
|
||||
@@ -114,8 +114,8 @@ int rs_init(struct rs_codec **out, unsigned n, unsigned r, size_t block_size) {
|
||||
ctx->work = ctx->storage + n * k;
|
||||
unsigned value = 1;
|
||||
for (unsigned i = 0; i < 255; i++) {
|
||||
ctx->gf_exp[i] = value;
|
||||
ctx->gf_log[value] = i;
|
||||
ctx->gf_exp[i] = (uint8_t)value;
|
||||
ctx->gf_log[value] = (uint8_t)i;
|
||||
value <<= 1;
|
||||
if (value & 256) value ^= 0x11d;
|
||||
}
|
||||
|
||||
@@ -71,10 +71,10 @@ static void fixture_init(struct fixture *f, unsigned n, unsigned r, size_t block
|
||||
f->input_size = rs_input_size(f->ctx);
|
||||
CHECK(f->input_size == f->k * (block_size - RS_HEADER_SIZE));
|
||||
f->storage_size = n * (block_size + 2 * GUARD);
|
||||
f->input_storage = u_malloc(f->input_size + 2 * GUARD);
|
||||
f->output_storage = u_malloc(f->input_size + 2 * GUARD);
|
||||
f->storage = u_malloc(f->storage_size);
|
||||
f->saved = u_malloc(f->storage_size);
|
||||
f->input_storage = u_malloc((uint32_t)(f->input_size + 2 * GUARD));
|
||||
f->output_storage = u_malloc((uint32_t)(f->input_size + 2 * GUARD));
|
||||
f->storage = u_malloc((uint32_t)f->storage_size);
|
||||
f->saved = u_malloc((uint32_t)f->storage_size);
|
||||
CHECK(f->input_storage && f->output_storage && f->storage && f->saved);
|
||||
memset(f->input_storage, MARKER, f->input_size + 2 * GUARD);
|
||||
memset(f->output_storage, MARKER, f->input_size + 2 * GUARD);
|
||||
@@ -293,8 +293,8 @@ static void test_stream(void) {
|
||||
struct fixture f;
|
||||
fixture_init(&f, 16, 2, 101, 0);
|
||||
size_t length = 3 * f.input_size + 17;
|
||||
uint8_t *source = u_malloc(length);
|
||||
uint8_t *result = u_malloc(length);
|
||||
uint8_t *source = u_malloc((uint32_t)length);
|
||||
uint8_t *result = u_malloc((uint32_t)length);
|
||||
CHECK(source && result);
|
||||
for (size_t i = 0; i < length; i++) source[i] = (uint8_t)(i * 17 + i / 251);
|
||||
size_t offset = 0;
|
||||
|
||||
Reference in new issue
Block a user