Skip to content

Commit

Permalink
Enabled uper C tests again and fixed them
Browse files Browse the repository at this point in the history
  • Loading branch information
Futsch1 committed Oct 21, 2023
1 parent 786155a commit ff00593
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ CC = gcc
endif

C_SOURCES := \
tests/files/c_source/oer.c
# tests/files/c_source/uper.c
tests/files/c_source/oer.c \
tests/files/c_source/uper.c

FUZZER_CC ?= clang
FUZZER_OER_EXE = main_oer_fuzzer
Expand Down
35 changes: 23 additions & 12 deletions asn1tools/source/c/uper.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def generate_definition_inner_process(self, type_, checker):
elif isinstance(type_, uper.OctetString):
return self.format_octet_string_inner(type_, checker)
elif isinstance(type_, uper.BitString):
return self.format_bit_string_inner(type_)
return self.format_bit_string_inner(type_, checker)
elif isinstance(type_, uper.Enumerated):
return self.format_enumerated_inner(type_)
elif isinstance(type_, uper.Null):
Expand Down Expand Up @@ -152,16 +152,19 @@ def format_integer_inner(self, type_, checker):
' {});'.format(type_.number_of_bits)
],
[
'dst_p->{} = decoder_read_non_negative_binary_integer('.format(
location),
'dst_p->{} = ({})decoder_read_non_negative_binary_integer('.format(
location,
type_name),
' decoder_p,',
' {});'.format(type_.number_of_bits),
'dst_p->{} += {};'.format(location, checker.minimum)
]
)

def format_bit_string_inner(self, type_):
def format_bit_string_inner(self, type_, checker):
location = self.location_inner()
max_value = 2 ** checker.minimum - 1
type_name = self.format_type_name(max_value, max_value)

return (
[
Expand All @@ -171,8 +174,9 @@ def format_bit_string_inner(self, type_):
' {});'.format(type_.maximum)
],
[
'dst_p->{} = decoder_read_non_negative_binary_integer('.format(
location),
'dst_p->{} = ({})decoder_read_non_negative_binary_integer('.format(
location,
type_name),
' decoder_p,',
' {});'.format(type_.maximum)
]
Expand Down Expand Up @@ -279,6 +283,10 @@ def format_sequence_inner(self, type_, checker):

def format_octet_string_inner(self, type_, checker):
location = self.location_inner('', '.')
if checker.maximum < 256:
length_type = 'uint8_t'
else:
length_type = 'uint32_t'

if checker.minimum == checker.maximum:
encode_lines = [
Expand All @@ -302,8 +310,9 @@ def format_octet_string_inner(self, type_, checker):
' src_p->{}length);'.format(location)
]
decode_lines = [
'dst_p->{}length = decoder_read_non_negative_binary_integer('.format(
location),
'dst_p->{}length = ({})decoder_read_non_negative_binary_integer('.format(
location,
length_type),
' decoder_p,',
' {});'.format(type_.number_of_bits),
'dst_p->{}length += {}u;'.format(location, checker.minimum)
Expand Down Expand Up @@ -459,8 +468,9 @@ def format_enumerated_inner(self, type_):
'{}, {});'.format(unique_value, type_.root_number_of_bits))

decode_lines = [
'{} = decoder_read_non_negative_binary_integer('
'{} = ({})decoder_read_non_negative_binary_integer('
'decoder_p, {});'.format(unique_value,
type_name,
type_.root_number_of_bits)
]

Expand Down Expand Up @@ -542,8 +552,9 @@ def format_sequence_of_inner(self, type_, checker):
location)
]
first_decode_lines = [
'dst_p->{}length = decoder_read_non_negative_binary_integer('.format(
location),
'dst_p->{}length = ({})decoder_read_non_negative_binary_integer('.format(
location,
type_name),
' decoder_p,',
' {});'.format(type_.number_of_bits),
'dst_p->{}length += {}u;'.format(location, checker.minimum),
Expand Down Expand Up @@ -596,7 +607,7 @@ def format_type_inner(self, type_, checker):
elif isinstance(type_, uper.Enumerated):
return self.format_enumerated_inner(type_)
elif isinstance(type_, uper.BitString):
return self.format_bit_string_inner(type_)
return self.format_bit_string_inner(type_, checker)
else:
raise self.error(type_)

Expand Down
2 changes: 1 addition & 1 deletion asn1tools/source/c/uper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
DECODER_READ_UINT8 = '''
static uint8_t decoder_read_uint8(struct decoder_t *self_p)
{
uint8_t value;
uint8_t value = 0;
decoder_read_bytes(self_p, &value, sizeof(value));
Expand Down
Loading

0 comments on commit ff00593

Please sign in to comment.