From 26191dc4a97f1434d14f8a579be4634c07192ea4 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Fri, 1 Oct 2021 18:23:25 -0500 Subject: [PATCH] parser: reset fixed flag each for each array If a message contains an array, we need to reset the flag that indicates whether it is a fixed array or not each time through the loop parsing message members. Otherwise a non-fixed array declared after a fixed array will be marked as fixed. Drop the "int" in the definition of the array_size local varaible in qmi_message_parse() to be consistent with the rest of the program. Signed-off-by: Alex Elder Message-Id: <20211001232338.769309-22-elder@linaro.org> Signed-off-by: Bjorn Andersson --- parser.c | 9 +++++---- tests/fixed.qmi | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/fixed.qmi diff --git a/parser.c b/parser.c index 2f3aa5c..7e93175 100644 --- a/parser.c +++ b/parser.c @@ -325,8 +325,8 @@ static void qmi_message_parse(enum message_type message_type) struct token type_tok; struct token num_tok; struct token id_tok; - unsigned int array_size; - bool array_fixed = false; + unsigned array_size; + bool array_fixed; bool required; token_expect(TOK_ID, &msg_id_tok); @@ -352,14 +352,15 @@ static void qmi_message_parse(enum message_type message_type) token_expect(TOK_NUM, &num_tok); array_size = num_tok.num; token_expect(']', NULL); - array_fixed = true; - } else if(token_accept('(', NULL)) { + } else if (token_accept('(', NULL)) { token_expect(TOK_NUM, &num_tok); array_size = num_tok.num; token_expect(')', NULL); + array_fixed = false; } else { array_size = 0; + array_fixed = false; } token_expect('=', NULL); diff --git a/tests/fixed.qmi b/tests/fixed.qmi new file mode 100644 index 0000000..c6376ed --- /dev/null +++ b/tests/fixed.qmi @@ -0,0 +1,17 @@ +package test; + +struct qmi_result { + u16 result; + u16 error; +}; + +request test_request { + optional u8 variable(5) = 0x1; + optional u16 fixed[5] = 0x2; + # The next field should have array_type VAR_LEN_ARRAY + optional u32 not_fixed(5) = 0x3; +} = 0x23; + +response test_response { + required qmi_result r = 2; +} = 043;