Commit 20325523 authored by Kai Vogelgesang's avatar Kai Vogelgesang Committed by rna

Add consistency checks to PrrtCodingConfiguration_create

parent dafefe33
......@@ -6,11 +6,32 @@
PrrtCodingConfiguration *PrrtCodingConfiguration_create(uint8_t k, uint8_t n, uint8_t c, uint8_t *n_cycle)
{
if (n < k) {
PERROR("Invalid parameters: n must be greater or equal k.%s","");
return NULL;
}
uint8_t r = n - k;
if ((r > 0) && (n_cycle == NULL)) {
PERROR("Invalid parameters: n_cycle cannot be NULL if (n-k) != 0.%s","");
return NULL;
}
uint8_t sum = 0;
for (int i = 0; i < c; ++i) {
sum += n_cycle[i];
}
if (sum != r) {
PERROR("Invalid parameters: The elements in n_cycle must sum up to n-k.%s","");
return NULL;
}
PrrtCodingConfiguration *cc = calloc(1, sizeof(PrrtCodingConfiguration));
check_mem(cc);
cc->k = k;
cc->n = n;
cc->r = cc->n - cc->k;
cc->r = r;
cc->c = c;
if(n_cycle != NULL) {
cc->n_cycle = (uint8_t*) realloc(cc->n_cycle, cc->c * sizeof(int8_t));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment