Skip to content

Commit de69116

Browse files
committed
increase int buffer and code cleanup
Signed-off-by: Siebren <[email protected]>
1 parent b76f818 commit de69116

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

src/input/code_templates/c/static_code/exi_basetypes.c.jinja

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,33 +120,33 @@ int exi_basetypes_convert_64_from_unsigned(const exi_unsigned_t* exi_unsigned, u
120120

121121
int exi_basetypes_convert_from_signed(const exi_signed_t* exi_signed, int32_t* value, size_t max_octets)
122122
{
123-
uint32_t uValue = 0;
124-
int res = exi_basetypes_convert_from_unsigned(&exi_signed->data, &uValue, max_octets);
125-
*value = (exi_signed->is_negative == 0) ? uValue : -uValue;
123+
uint32_t u_value = 0;
124+
int res = exi_basetypes_convert_from_unsigned(&exi_signed->data, &u_value, max_octets);
125+
*value = (exi_signed->is_negative == 0) ? u_value : -u_value;
126126
return res;
127127
}
128128

129129
int exi_basetypes_convert_64_from_signed(const exi_signed_t* exi_signed, int64_t* value)
130130
{
131-
uint64_t uValue = 0;
132-
int res = exi_basetypes_convert_64_from_unsigned(&exi_signed->data, &uValue);
133-
*value = (exi_signed->is_negative == 0) ? uValue : -uValue;
131+
uint64_t u_value = 0;
132+
int res = exi_basetypes_convert_64_from_unsigned(&exi_signed->data, &u_value);
133+
*value = (exi_signed->is_negative == 0) ? u_value : -u_value;
134134
return res;
135135
}
136136

137137
int exi_basetypes_convert_bytes_from_unsigned(const exi_unsigned_t* exi_unsigned, uint8_t* data, size_t* data_len, size_t data_size)
138-
{
138+
{
139139
const uint8_t* current_octet = exi_unsigned->octets;
140140
uint16_t temp = 0;
141141
*data_len = 0;
142142
size_t total_offset = 0;
143143

144144
for (size_t n = 0; n < exi_unsigned->octets_count; n++) {
145-
temp = temp + ((uint16_t)(*current_octet & EXI_BASETYPES_OCTET_SEQ_VALUE_MASK) << (total_offset));
145+
temp += ((uint16_t)(*current_octet & EXI_BASETYPES_OCTET_SEQ_VALUE_MASK) << total_offset);
146146
total_offset += 7;
147147
if (total_offset >= 8) {
148148
if (data_size == *data_len) {
149-
return -1;
149+
return EXI_ERROR__ENCODED_INTEGER_SIZE_LARGER_THAN_DESTINATION;
150150
}
151151
total_offset -= 8;
152152
data[(*data_len)++] = temp & 0xFF;
@@ -156,11 +156,11 @@ int exi_basetypes_convert_bytes_from_unsigned(const exi_unsigned_t* exi_unsigned
156156
}
157157
if (total_offset != 0) {
158158
if (data_size == *data_len) {
159-
return -1;
159+
return EXI_ERROR__ENCODED_INTEGER_SIZE_LARGER_THAN_DESTINATION;
160160
}
161161
data[(*data_len)++] = temp & 0xFF;
162162
}
163-
return 0;
163+
return EXI_ERROR__NO_ERROR;
164164
}
165165

166166
int exi_basetypes_convert_bytes_to_unsigned(exi_unsigned_t* exi_unsigned, const uint8_t* data, size_t data_len)
@@ -171,13 +171,13 @@ int exi_basetypes_convert_bytes_to_unsigned(exi_unsigned_t* exi_unsigned, const
171171

172172
for (size_t n = 0; n != data_len; n++, current_octet++) {
173173
if (dummy_count <= 8) {
174-
dummy = dummy | ((data[n]) << dummy_count);
174+
dummy |= (data[n] << dummy_count);
175175
dummy_count += 8;
176176
}
177177
exi_unsigned->octets_count++;
178178
*current_octet = (uint8_t)(dummy & EXI_BASETYPES_OCTET_SEQ_VALUE_MASK);
179179

180-
dummy = dummy >> 7u;
180+
dummy >>= 7u;
181181
dummy_count -= 7;
182182
if (n == data_len) {
183183
break;
@@ -190,7 +190,7 @@ int exi_basetypes_convert_bytes_to_unsigned(exi_unsigned_t* exi_unsigned, const
190190
exi_unsigned->octets_count++;
191191
*current_octet = (uint8_t)(dummy & EXI_BASETYPES_OCTET_SEQ_VALUE_MASK);
192192
}
193-
return 0;
193+
return EXI_ERROR__NO_ERROR;
194194
}
195195

196196
{% endblock %}

src/input/code_templates/c/static_code/exi_basetypes.h.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define EXI_STRING_MAX_LEN 64
1717
#define EXI_BYTE_ARRAY_MAX_LEN 350
1818

19-
#define EXI_BASETYPES_MAX_OCTETS_SUPPORTED 20
19+
#define EXI_BASETYPES_MAX_OCTETS_SUPPORTED 29
2020

2121
#define EXI_BASETYPES_OCTET_SEQ_FLAG_MASK 0x80
2222
#define EXI_BASETYPES_OCTET_SEQ_VALUE_MASK 0x7F

src/input/code_templates/c/static_code/exi_basetypes_decoder.c.jinja

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,9 @@ int exi_basetypes_decoder_integer_64(exi_bitstream_t* stream, int64_t* value)
348348

349349
int exi_basetypes_decoder_signed(exi_bitstream_t* stream, exi_signed_t* value)
350350
{
351-
int sign;
352-
int error;
351+
int sign = 0;
353352

354-
error = exi_basetypes_decoder_bool(stream, &sign);
353+
int error = exi_basetypes_decoder_bool(stream, &sign);
355354
if (error != EXI_ERROR__NO_ERROR)
356355
{
357356
return error;

src/input/code_templates/c/static_code/exi_basetypes_encoder.c.jinja

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ int exi_basetypes_encoder_integer_64(exi_bitstream_t* stream, int64_t value)
285285

286286
int exi_basetypes_encoder_signed(exi_bitstream_t* stream, const exi_signed_t* value)
287287
{
288-
int error;
289-
290-
error = exi_basetypes_encoder_bool(stream, value->is_negative);
288+
int error = exi_basetypes_encoder_bool(stream, value->is_negative);
291289
if (error != EXI_ERROR__NO_ERROR)
292290
{
293291
return error;

src/input/code_templates/c/static_code/exi_error_codes.h.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define EXI_ERROR__ARRAY_OUT_OF_BOUNDS -110
3131
#define EXI_ERROR__CHARACTER_BUFFER_TOO_SMALL -111
3232
#define EXI_ERROR__BYTE_BUFFER_TOO_SMALL -112
33+
#define EXI_ERROR__ENCODED_INTEGER_SIZE_LARGER_THAN_DESTINATION -113
3334

3435
// grammar errors -130 to -149
3536
#define EXI_ERROR__UNKNOWN_GRAMMAR_ID -130

0 commit comments

Comments
 (0)