Skip to content

Commit

Permalink
include/msvcpdb.h: Use flexible array members for codeview_fieldtype …
Browse files Browse the repository at this point in the history
…union.

This will avoid GCC compiler warnings.

Signed-off-by: Eric Pouech <epouech@codeweavers.com>
  • Loading branch information
Eric Pouech authored and julliard committed Jul 16, 2024
1 parent a95ba55 commit 5db354f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 77 deletions.
54 changes: 30 additions & 24 deletions dlls/dbghelp/msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -888,17 +894,17 @@ 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);
break;
}
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));
Expand Down Expand Up @@ -990,15 +996,15 @@ 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 */

ptr += 2 + 2 + 2 + leaf_len;
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 */

Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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);

Expand Down
55 changes: 25 additions & 30 deletions include/wine/mscvpdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,17 @@ union codeview_fieldtype
unsigned short int id;
cv_typ16_t type;
short int attribute;
unsigned short int offset; /* numeric leaf */
unsigned char data[];
/* <numeric leaf> offset; */
} bclass_v1;

struct
{
unsigned short int id;
short int attribute;
cv_typ_t type;
unsigned short int offset; /* numeric leaf */
unsigned char data[];
/* <numeric leaf> offset; */
} bclass_v2;

struct
Expand All @@ -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[];
/* <numeric leaf> vbpoff; */
/* <numeric leaf> vboff; */
} vbclass_v1;

struct
Expand All @@ -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[];
/* <numeric leaf> vbpoff; */
/* <numeric leaf> 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[];
/* <numeric leaf> 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[];
/* <numeric leaf> value; */
/* char name[]; */
} enumerate_v3;

struct
Expand Down Expand Up @@ -608,32 +606,29 @@ 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[];
/* <numeric leaf> offset; */
/* struct p_string p_name; */
} member_v1;

struct
{
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[];
/* <numeric leaf> offset; */
/* struct p_string p_name; */
} member_v2;

struct
{
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[];
/* <numeric leaf> offset; */
/* char name[]; */
}
member_v3;

Expand Down
51 changes: 28 additions & 23 deletions tools/winedump/msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -518,44 +523,44 @@ 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);
ptr += 2 + 2 + 2 + leaf_len + 1 + pstr->namelen;
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);
ptr += 2 + 2 + 4 + leaf_len + 1 + pstr->namelen;
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5db354f

Please sign in to comment.