From 5db354f9529e70c05af5c1e90a0065090e3772fc Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Sat, 8 Jun 2024 10:06:31 +0200 Subject: [PATCH] include/msvcpdb.h: Use flexible array members for codeview_fieldtype union. This will avoid GCC compiler warnings. Signed-off-by: Eric Pouech --- dlls/dbghelp/msc.c | 54 +++++++++++++++++++++++------------------ include/wine/mscvpdb.h | 55 +++++++++++++++++++----------------------- tools/winedump/msc.c | 51 +++++++++++++++++++++------------------ 3 files changed, 83 insertions(+), 77 deletions(-) diff --git a/dlls/dbghelp/msc.c b/dlls/dbghelp/msc.c index 546b9d83d746..04de7f6491fa 100644 --- a/dlls/dbghelp/msc.c +++ b/dlls/dbghelp/msc.c @@ -269,10 +269,13 @@ static void codeview_init_basic_types(struct module* module) cv_basic_types[T_PUINT8] = &symt_new_pointer(module, cv_basic_types[T_UINT8], ptrsz)->symt; } -static int leaf_as_variant(VARIANT* v, const unsigned short int* leaf) +/* wrapper for migration to FAM */ +#define leaf_as_variant(v, l) _leaf_as_variant((v), (const unsigned char*)(l)) +static int _leaf_as_variant(VARIANT *v, const unsigned char *leaf) { - unsigned short int type = *leaf++; + unsigned short int type = *(const unsigned short *)leaf; int length = 2; + leaf += length; if (type < LF_NUMERIC) { @@ -394,10 +397,13 @@ static int leaf_as_variant(VARIANT* v, const unsigned short int* leaf) return length; } -static int numeric_leaf(int* value, const unsigned short int* leaf) +/* wrapper for migration to FAM */ +#define numeric_leaf(v, l) _numeric_leaf(v, (const unsigned char *)(l)) +static int _numeric_leaf(int *value, const unsigned char *leaf) { - unsigned short int type = *leaf++; + unsigned short int type = *(const unsigned short int *)leaf; int length = 2; + leaf += length; if (type < LF_NUMERIC) { @@ -888,8 +894,8 @@ static BOOL codeview_add_type_enum_field_list(struct codeview_type_parse* ctp, { case LF_ENUMERATE_V1: { - int value, vlen = numeric_leaf(&value, &type->enumerate_v1.value); - const struct p_string* p_name = (const struct p_string*)((const unsigned char*)&type->enumerate_v1.value + vlen); + int value, vlen = numeric_leaf(&value, type->enumerate_v1.data); + const struct p_string* p_name = (const struct p_string*)&type->enumerate_v1.data[vlen]; symt_add_enum_element(ctp->module, symt, terminate_string(p_name), value); ptr += 2 + 2 + vlen + (1 + p_name->namelen); @@ -897,8 +903,8 @@ static BOOL codeview_add_type_enum_field_list(struct codeview_type_parse* ctp, } case LF_ENUMERATE_V3: { - int value, vlen = numeric_leaf(&value, &type->enumerate_v3.value); - const char* name = (const char*)&type->enumerate_v3.value + vlen; + int value, vlen = numeric_leaf(&value, type->enumerate_v3.data); + const char* name = (const char*)&type->enumerate_v3.data[vlen]; symt_add_enum_element(ctp->module, symt, name, value); ptr += 2 + 2 + vlen + (1 + strlen(name)); @@ -990,7 +996,7 @@ static int codeview_add_type_struct_field_list(struct codeview_type_parse* ctp, switch (type->generic.id) { case LF_BCLASS_V1: - leaf_len = numeric_leaf(&value, &type->bclass_v1.offset); + leaf_len = numeric_leaf(&value, type->bclass_v1.data); /* FIXME: ignored for now */ @@ -998,7 +1004,7 @@ static int codeview_add_type_struct_field_list(struct codeview_type_parse* ctp, break; case LF_BCLASS_V2: - leaf_len = numeric_leaf(&value, &type->bclass_v2.offset); + leaf_len = numeric_leaf(&value, type->bclass_v2.data); /* FIXME: ignored for now */ @@ -1008,10 +1014,10 @@ static int codeview_add_type_struct_field_list(struct codeview_type_parse* ctp, case LF_VBCLASS_V1: case LF_IVBCLASS_V1: { - const unsigned short int* p_vboff; + const unsigned char* p_vboff; int vpoff, vplen; - leaf_len = numeric_leaf(&value, &type->vbclass_v1.vbpoff); - p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v1.vbpoff + leaf_len); + leaf_len = numeric_leaf(&value, type->vbclass_v1.data); + p_vboff = &type->vbclass_v1.data[leaf_len]; vplen = numeric_leaf(&vpoff, p_vboff); /* FIXME: ignored for now */ @@ -1023,10 +1029,10 @@ static int codeview_add_type_struct_field_list(struct codeview_type_parse* ctp, case LF_VBCLASS_V2: case LF_IVBCLASS_V2: { - const unsigned short int* p_vboff; + const unsigned char* p_vboff; int vpoff, vplen; - leaf_len = numeric_leaf(&value, &type->vbclass_v2.vbpoff); - p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v2.vbpoff + leaf_len); + leaf_len = numeric_leaf(&value, type->vbclass_v2.data); + p_vboff = &type->vbclass_v2.data[leaf_len]; vplen = numeric_leaf(&vpoff, p_vboff); /* FIXME: ignored for now */ @@ -1036,28 +1042,28 @@ static int codeview_add_type_struct_field_list(struct codeview_type_parse* ctp, break; case LF_MEMBER_V1: - leaf_len = numeric_leaf(&value, &type->member_v1.offset); - p_name = (const struct p_string*)((const char*)&type->member_v1.offset + leaf_len); + leaf_len = numeric_leaf(&value, type->member_v1.data); + p_name = (const struct p_string*)&type->member_v1.data[leaf_len]; - codeview_add_udt_element(ctp, symt, terminate_string(p_name), value, + codeview_add_udt_element(ctp, symt, terminate_string(p_name), value, type->member_v1.type); ptr += 2 + 2 + 2 + leaf_len + (1 + p_name->namelen); break; case LF_MEMBER_V2: - leaf_len = numeric_leaf(&value, &type->member_v2.offset); - p_name = (const struct p_string*)((const unsigned char*)&type->member_v2.offset + leaf_len); + leaf_len = numeric_leaf(&value, type->member_v2.data); + p_name = (const struct p_string*)&type->member_v2.data[leaf_len]; - codeview_add_udt_element(ctp, symt, terminate_string(p_name), value, + codeview_add_udt_element(ctp, symt, terminate_string(p_name), value, type->member_v2.type); ptr += 2 + 2 + 4 + leaf_len + (1 + p_name->namelen); break; case LF_MEMBER_V3: - leaf_len = numeric_leaf(&value, &type->member_v3.offset); - c_name = (const char*)&type->member_v3.offset + leaf_len; + leaf_len = numeric_leaf(&value, type->member_v3.data); + c_name = (const char*)&type->member_v3.data[leaf_len]; codeview_add_udt_element(ctp, symt, c_name, value, type->member_v3.type); diff --git a/include/wine/mscvpdb.h b/include/wine/mscvpdb.h index 72626a23a2d2..da66b2c24164 100644 --- a/include/wine/mscvpdb.h +++ b/include/wine/mscvpdb.h @@ -525,7 +525,8 @@ union codeview_fieldtype unsigned short int id; cv_typ16_t type; short int attribute; - unsigned short int offset; /* numeric leaf */ + unsigned char data[]; + /* offset; */ } bclass_v1; struct @@ -533,7 +534,8 @@ union codeview_fieldtype unsigned short int id; short int attribute; cv_typ_t type; - unsigned short int offset; /* numeric leaf */ + unsigned char data[]; + /* offset; */ } bclass_v2; struct @@ -542,10 +544,9 @@ union codeview_fieldtype cv_typ16_t btype; cv_typ16_t vbtype; short int attribute; - unsigned short int vbpoff; /* numeric leaf */ -#if 0 - unsigned short int vboff; /* numeric leaf */ -#endif + unsigned char data[]; + /* vbpoff; */ + /* vboff; */ } vbclass_v1; struct @@ -554,30 +555,27 @@ union codeview_fieldtype short int attribute; cv_typ_t btype; cv_typ_t vbtype; - unsigned short int vbpoff; /* numeric leaf */ -#if 0 - unsigned short int vboff; /* numeric leaf */ -#endif + unsigned char data[]; + /* vbpoff; */ + /* vboff; */ } vbclass_v2; struct { unsigned short int id; short int attribute; - unsigned short int value; /* numeric leaf */ -#if 0 - struct p_string p_name; -#endif + unsigned char data[]; + /* value; */ + /* struct p_string p_name; */ } enumerate_v1; struct { unsigned short int id; short int attribute; - unsigned short int value; /* numeric leaf */ -#if 0 - char name[1]; -#endif + unsigned char data[]; + /* value; */ + /* char name[]; */ } enumerate_v3; struct @@ -608,10 +606,9 @@ union codeview_fieldtype unsigned short int id; cv_typ16_t type; short int attribute; - unsigned short int offset; /* numeric leaf */ -#if 0 - struct p_string p_name; -#endif + unsigned char data[]; + /* offset; */ + /* struct p_string p_name; */ } member_v1; struct @@ -619,10 +616,9 @@ union codeview_fieldtype unsigned short int id; short int attribute; cv_typ_t type; - unsigned short int offset; /* numeric leaf */ -#if 0 - struct p_string p_name; -#endif + unsigned char data[]; + /* offset; */ + /* struct p_string p_name; */ } member_v2; struct @@ -630,10 +626,9 @@ union codeview_fieldtype unsigned short int id; short int attribute; cv_typ_t type; - unsigned short int offset; /* numeric leaf */ -#if 0 - char name[1]; -#endif + unsigned char data[]; + /* offset; */ + /* char name[]; */ } member_v3; diff --git a/tools/winedump/msc.c b/tools/winedump/msc.c index cb5fbb0b9ad6..5e274b730dd7 100644 --- a/tools/winedump/msc.c +++ b/tools/winedump/msc.c @@ -52,11 +52,14 @@ struct full_value } v; }; -static int full_numeric_leaf(struct full_value* fv, const unsigned short int* leaf) +/* wrapper for migration to FAM */ +#define full_numeric_leaf(f, l) _full_numeric_leaf((f), (const unsigned char *)(l)) +static int _full_numeric_leaf(struct full_value *fv, const unsigned char *leaf) { - unsigned short int type = *leaf++; + unsigned short int type = *(const unsigned short *)leaf; int length = 2; + leaf += length; fv->type = fv_integer; if (type < LF_NUMERIC) { @@ -184,10 +187,12 @@ static const char* full_value_string(const struct full_value* fv) return tmp; } -static int numeric_leaf(int* value, const unsigned short int* leaf) +/* wrapper for migration to FAM */ +#define numeric_leaf(v, l) _numeric_leaf((v), (const unsigned char *)(l)) +static int _numeric_leaf(int* value, const unsigned char* leaf) { struct full_value fv; - int len = full_numeric_leaf(&fv, leaf); + int len = _full_numeric_leaf(&fv, leaf); switch (fv.type) { @@ -518,24 +523,24 @@ static void do_field(const unsigned char* start, const unsigned char* end) switch (fieldtype->generic.id) { case LF_ENUMERATE_V1: - leaf_len = full_numeric_leaf(&full_value, &fieldtype->enumerate_v1.value); - pstr = PSTRING(&fieldtype->enumerate_v1.value, leaf_len); + leaf_len = full_numeric_leaf(&full_value, fieldtype->enumerate_v1.data); + pstr = (const struct p_string*)&fieldtype->enumerate_v1.data[leaf_len]; printf("\t\tEnumerate V1: '%s' value:%s\n", p_string(pstr), full_value_string(&full_value)); ptr += 2 + 2 + leaf_len + 1 + pstr->namelen; break; case LF_ENUMERATE_V3: - leaf_len = full_numeric_leaf(&full_value, &fieldtype->enumerate_v3.value); - cstr = (const char*)&fieldtype->enumerate_v3.value + leaf_len; + leaf_len = full_numeric_leaf(&full_value, fieldtype->enumerate_v3.data); + cstr = (const char*)&fieldtype->enumerate_v3.data[leaf_len]; printf("\t\tEnumerate V3: '%s' value:%s\n", cstr, full_value_string(&full_value)); ptr += 2 + 2 + leaf_len + strlen(cstr) + 1; break; case LF_MEMBER_V1: - leaf_len = numeric_leaf(&value, &fieldtype->member_v1.offset); - pstr = PSTRING(&fieldtype->member_v1.offset, leaf_len); + leaf_len = numeric_leaf(&value, fieldtype->member_v1.data); + pstr = (const struct p_string *)&fieldtype->member_v1.data[leaf_len]; printf("\t\tMember V1: '%s' type:%x attr:%s @%d\n", p_string(pstr), fieldtype->member_v1.type, get_attr(fieldtype->member_v1.attribute), value); @@ -543,8 +548,8 @@ static void do_field(const unsigned char* start, const unsigned char* end) break; case LF_MEMBER_V2: - leaf_len = numeric_leaf(&value, &fieldtype->member_v2.offset); - pstr = PSTRING(&fieldtype->member_v2.offset, leaf_len); + leaf_len = numeric_leaf(&value, fieldtype->member_v2.data); + pstr = (const struct p_string *)&fieldtype->member_v2.data[leaf_len]; printf("\t\tMember V2: '%s' type:%x attr:%s @%d\n", p_string(pstr), fieldtype->member_v2.type, get_attr(fieldtype->member_v2.attribute), value); @@ -552,10 +557,10 @@ static void do_field(const unsigned char* start, const unsigned char* end) break; case LF_MEMBER_V3: - leaf_len = numeric_leaf(&value, &fieldtype->member_v3.offset); - cstr = (const char*)&fieldtype->member_v3.offset + leaf_len; + leaf_len = numeric_leaf(&value, fieldtype->member_v3.data); + cstr = (const char*)&fieldtype->member_v3.data[leaf_len]; printf("\t\tMember V3: '%s' type:%x attr:%s @%d\n", - cstr, fieldtype->member_v3.type, + cstr, fieldtype->member_v3.type, get_attr(fieldtype->member_v3.attribute), value); ptr += 2 + 2 + 4 + leaf_len + strlen(cstr) + 1; break; @@ -693,43 +698,43 @@ static void do_field(const unsigned char* start, const unsigned char* end) break; case LF_BCLASS_V1: - leaf_len = numeric_leaf(&value, &fieldtype->bclass_v1.offset); + leaf_len = numeric_leaf(&value, fieldtype->bclass_v1.data); printf("\t\tBase class V1: type:%x attr:%s @%d\n", - fieldtype->bclass_v1.type, + fieldtype->bclass_v1.type, get_attr(fieldtype->bclass_v1.attribute), value); ptr += 2 + 2 + 2 + leaf_len; break; case LF_BCLASS_V2: - leaf_len = numeric_leaf(&value, &fieldtype->bclass_v2.offset); + leaf_len = numeric_leaf(&value, fieldtype->bclass_v2.data); printf("\t\tBase class V2: type:%x attr:%s @%d\n", - fieldtype->bclass_v2.type, + fieldtype->bclass_v2.type, get_attr(fieldtype->bclass_v2.attribute), value); ptr += 2 + 2 + 4 + leaf_len; break; case LF_VBCLASS_V1: case LF_IVBCLASS_V1: - leaf_len = numeric_leaf(&value, &fieldtype->vbclass_v1.vbpoff); + leaf_len = numeric_leaf(&value, fieldtype->vbclass_v1.data); printf("\t\t%sirtual base class V1: type:%x (ptr:%x) attr:%s vbpoff:%d ", (fieldtype->generic.id == LF_VBCLASS_V2) ? "V" : "Indirect v", fieldtype->vbclass_v1.btype, fieldtype->vbclass_v1.vbtype, get_attr(fieldtype->vbclass_v1.attribute), value); ptr += 2 + 2 + 2 + 2 + leaf_len; - leaf_len = numeric_leaf(&value, (const unsigned short*)ptr); + leaf_len = numeric_leaf(&value, ptr); printf("vboff:%d\n", value); ptr += leaf_len; break; case LF_VBCLASS_V2: case LF_IVBCLASS_V2: - leaf_len = numeric_leaf(&value, &fieldtype->vbclass_v1.vbpoff); + leaf_len = numeric_leaf(&value, fieldtype->vbclass_v1.data); printf("\t\t%sirtual base class V2: type:%x (ptr:%x) attr:%s vbpoff:%d ", (fieldtype->generic.id == LF_VBCLASS_V2) ? "V" : "Indirect v", fieldtype->vbclass_v2.btype, fieldtype->vbclass_v2.vbtype, get_attr(fieldtype->vbclass_v2.attribute), value); ptr += 2 + 2 + 4 + 4 + leaf_len; - leaf_len = numeric_leaf(&value, (const unsigned short*)ptr); + leaf_len = numeric_leaf(&value, ptr); printf("vboff:%d\n", value); ptr += leaf_len; break;