From 58a9418411eb13530349887df93b2c96febbd23f Mon Sep 17 00:00:00 2001
From: Dmitry Timoshkov <dmitry@baikal.ru>
Date: Sat, 9 Jan 2016 15:49:46 +0800
Subject: [PATCH] widl: More accurately report variable descriptions data size.

---
 tools/widl/write_sltg.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tools/widl/write_sltg.c b/tools/widl/write_sltg.c
index 216d688e69d..0d27898c7c0 100644
--- a/tools/widl/write_sltg.c
+++ b/tools/widl/write_sltg.c
@@ -678,14 +678,15 @@ static void add_structure_typeinfo(struct sltg_typelib *typelib, const type_t *t
 
         LIST_FOR_EACH_ENTRY(var, type_struct_get_fields(type), var_t, entry)
         {
+            short base_offset;
+
             chat("add_structure_typeinfo: var %p, name %s, type %p\n",
                  var, var->name, var->declspec.type);
 
             init_sltg_data(&var_data[i]);
 
-            var_data_size += sizeof(struct sltg_variable);
-
-            type_desc_offset[i] = write_var_desc(&var_data[i], var->declspec.type, 0, var_data_size);
+            base_offset = var_data_size + (i + 1) * sizeof(struct sltg_variable);
+            type_desc_offset[i] = write_var_desc(&var_data[i], var->declspec.type, 0, base_offset);
             dump_var_desc(var_data[i].data, var_data[i].size);
 
             if (var_data[i].size > sizeof(short))
@@ -699,9 +700,11 @@ static void add_structure_typeinfo(struct sltg_typelib *typelib, const type_t *t
     member.res00 = 0x0001;
     member.res02 = 0xffff;
     member.res04 = 0x01;
-    member.extra = var_data_size;
+    member.extra = var_data_size + var_count * sizeof(struct sltg_variable);
     append_data(&data, &member, sizeof(member));
 
+    var_data_size = 0;
+
     if (type_struct_get_fields(type))
     {
         int i = 0;
@@ -720,7 +723,8 @@ static void add_structure_typeinfo(struct sltg_typelib *typelib, const type_t *t
             if (var_data[i].size > sizeof(short))
             {
                 variable.flags = 0;
-                variable.type = next - member_offset + type_desc_offset[i];
+                var_data_size = next - member_offset + type_desc_offset[i];
+                variable.type = var_data_size;
                 next += var_data[i].size;
             }
             else
@@ -760,15 +764,15 @@ static void add_structure_typeinfo(struct sltg_typelib *typelib, const type_t *t
     tail.res1e = 0;
     tail.cbSizeInstance = 0;
     tail.cbAlignment = 4;
-    tail.res24 = 0;
-    tail.res26 = 0;
+    tail.res24 = -1;
+    tail.res26 = -1;
     tail.cbSizeVft = 0;
     tail.res2a = -1;
     tail.res2c = -1;
     tail.res2e = -1;
     tail.res30 = -1;
     tail.res32 = 0;
-    tail.type_bytes = data.size - member_offset;
+    tail.type_bytes = data.size - member_offset - sizeof(member);
     append_data(&data, &tail, sizeof(tail));
 
     add_block(typelib, data.data, data.size, index_name);
-- 
2.17.1

