Fix for status/value parse bug.
This commit is contained in:
parent
b9229cb5af
commit
4b7114a8aa
3 changed files with 11 additions and 2 deletions
|
@ -35,7 +35,7 @@ sml_status *sml_status_parse(sml_buffer *buf) {
|
|||
int type = sml_buf_get_next_type(buf);
|
||||
unsigned char byte = sml_buf_get_current_byte(buf);
|
||||
|
||||
sml_status *status = (sml_status *) malloc(sizeof(sml_status));
|
||||
sml_status *status = sml_status_init();
|
||||
status->type = type;
|
||||
switch (type) {
|
||||
case SML_TYPE_UNSIGNED:
|
||||
|
|
|
@ -29,7 +29,7 @@ sml_value *sml_value_parse(sml_buffer *buf) {
|
|||
int type = sml_buf_get_next_type(buf);
|
||||
unsigned char byte = sml_buf_get_current_byte(buf);
|
||||
|
||||
sml_value *value = (sml_value *) malloc(sizeof(sml_value));
|
||||
sml_value *value = sml_value_init();
|
||||
value->type = type;
|
||||
|
||||
switch (type) {
|
||||
|
|
|
@ -55,6 +55,14 @@ TEST(sml_status, parse_optional) {
|
|||
TEST_ASSERT_EQUAL(1, buf->cursor);
|
||||
}
|
||||
|
||||
TEST(sml_status, parse_not_unsigned) {
|
||||
hex2binary("5001", sml_buf_get_current_buf(buf));
|
||||
sml_status *s = sml_status_parse(buf);
|
||||
|
||||
TEST_ASSERT_NULL(s);
|
||||
TEST_ASSERT_TRUE(sml_buf_has_errors(buf));
|
||||
}
|
||||
|
||||
TEST(sml_status, write_status32) {
|
||||
sml_status *s = sml_status_init();
|
||||
s->type = SML_TYPE_UNSIGNED | SML_TYPE_NUMBER_32;
|
||||
|
@ -74,6 +82,7 @@ TEST_GROUP_RUNNER(sml_status) {
|
|||
RUN_TEST_CASE(sml_status, init);
|
||||
RUN_TEST_CASE(sml_status, parse_status8);
|
||||
RUN_TEST_CASE(sml_status, parse_optional);
|
||||
RUN_TEST_CASE(sml_status, parse_not_unsigned);
|
||||
RUN_TEST_CASE(sml_status, write_status32);
|
||||
RUN_TEST_CASE(sml_status, write_optional);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue