Fix demarshaller code generator

Even though commit df4ec5c318 commented
out most of smartcard code which triggered this error, it still might
happen if a new message is added with an array member.

The reason is a missing declaration of mem_size, which is fixed simply
by checking if the attribute 'nocopy' is present.

The error log follows:

generated_server_demarshallers.c: In function ‘parse_msgc_smartcard_reader_add’:
generated_server_demarshallers.c:1985:30: error: ‘mem_size’ undeclared (first use in this function); did you mean ‘nw_size’?
     data = (uint8_t *)malloc(mem_size);
                              ^~~~~~~~
                              nw_size

This patch also updates test-marshallers so that this bug is triggered.

The diff between generated demarshallers with the patch applied follows:

--- tests/generated_test_demarshallers.c.old    2018-05-17 14:35:29.234056487 -0300
+++ tests/generated_test_demarshallers.c        2018-05-17 14:35:40.554031295 -0300
@@ -286,6 +286,7 @@ static uint8_t * parse_msg_main_ArrayMes
     uint8_t *start = message_start;
     uint8_t *data = NULL;
     uint64_t nw_size;
+    uint64_t mem_size;
     uint8_t *in, *end;
     uint64_t name__nw_size;
     uint64_t name__nelements;
@@ -298,6 +299,7 @@ static uint8_t * parse_msg_main_ArrayMes
     }

     nw_size = 0 + name__nw_size;
+    mem_size = sizeof(SpiceMsgMainArrayMessage);

     /* Check if message fits in reported side */
     if (nw_size > (uintptr_t) (message_end - start)) {

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Eduardo Lima (Etrunko) 2018-05-17 14:41:10 -03:00 committed by Frediano Ziglio
parent 129bd04766
commit 20bda4dba9
3 changed files with 9 additions and 2 deletions

View File

@ -1039,8 +1039,7 @@ def write_msg_parser(writer, message):
msg_type = message.c_type()
msg_sizeof = message.sizeof()
want_mem_size = (len(message.members) != 1 or message.members[0].is_fixed_nw_size()
or not message.members[0].is_array())
want_mem_size = not message.has_attr("nocopy")
writer.newline()
if message.has_attr("ifdef"):

View File

@ -8,5 +8,9 @@ typedef struct {
uint64_t *data;
} SpiceMsgMainShortDataSubMarshall;
typedef struct {
int8_t *name;
} SpiceMsgMainArrayMessage;
#endif /* _H_TEST_MARSHALLERS */

View File

@ -4,6 +4,10 @@ channel TestChannel {
uint32 data_size;
uint64 *data[data_size] @marshall;
} ShortDataSubMarshall;
message {
int8 name[];
} ArrayMessage;
};
protocol Spice {