Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LARN
PRRT
Commits
20325523
Commit
20325523
authored
Sep 05, 2018
by
Kai Vogelgesang
Committed by
rna
Sep 05, 2018
Browse files
Add consistency checks to PrrtCodingConfiguration_create
parent
dafefe33
Changes
1
Hide whitespace changes
Inline
Side-by-side
prrt/proto/types/codingParams.c
View file @
20325523
...
...
@@ -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
));
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment