Commit a407da47 authored by Dan Hipschman's avatar Dan Hipschman Committed by Alexandre Julliard

widl: Sanity check string and pointer attrs. Don't assign string as type.

parent 180ede5b
...@@ -1285,29 +1285,26 @@ static type_t *reg_type(type_t *type, const char *name, int t) ...@@ -1285,29 +1285,26 @@ static type_t *reg_type(type_t *type, const char *name, int t)
return type; return type;
} }
/* determine pointer type from attrs */
static unsigned char get_pointer_type( type_t *type )
{
int t;
if (is_attr( type->attrs, ATTR_STRING ))
{
switch( type->ref->type )
{
case RPC_FC_CHAR:
return RPC_FC_C_CSTRING;
case RPC_FC_WCHAR:
return RPC_FC_C_WSTRING;
}
}
t = get_attrv( type->attrs, ATTR_POINTERTYPE );
if (t) return t;
return RPC_FC_FP;
}
static type_t *reg_typedefs(type_t *type, var_t *names, attr_t *attrs) static type_t *reg_typedefs(type_t *type, var_t *names, attr_t *attrs)
{ {
type_t *ptr = type; type_t *ptr = type;
int ptrc = 0; int ptrc = 0;
int is_str = is_attr(attrs, ATTR_STRING);
unsigned char ptr_type = get_attrv(attrs, ATTR_POINTERTYPE);
if (is_str)
{
type_t *t = type;
unsigned char c;
while (is_ptr(t))
t = t->ref;
c = t->type;
if (c != RPC_FC_CHAR && c != RPC_FC_BYTE && c != RPC_FC_WCHAR)
yyerror("'%s': [string] attribute is only valid on 'char', 'byte', or 'wchar_t' pointers and arrays",
names->name);
}
/* We must generate names for tagless enum, struct or union. /* We must generate names for tagless enum, struct or union.
Typedef-ing a tagless enum, struct or union means we want the typedef Typedef-ing a tagless enum, struct or union means we want the typedef
...@@ -1343,8 +1340,18 @@ static type_t *reg_typedefs(type_t *type, var_t *names, attr_t *attrs) ...@@ -1343,8 +1340,18 @@ static type_t *reg_typedefs(type_t *type, var_t *names, attr_t *attrs)
} }
cur = alias(cur, names->name); cur = alias(cur, names->name);
cur->attrs = attrs; cur->attrs = attrs;
if (is_ptr(cur)) if (ptr_type)
cur->type = get_pointer_type(cur); {
if (is_ptr(cur))
cur->type = ptr_type;
else
yyerror("'%s': pointer attribute applied to non-pointer type",
cur->name);
}
else if (is_str && ! is_ptr(cur))
yyerror("'%s': [string] attribute applied to non-pointer type",
cur->name);
reg_type(cur, cur->name, 0); reg_type(cur, cur->name, 0);
} }
names = next; names = next;
...@@ -1485,11 +1492,6 @@ static int get_struct_type(var_t *field) ...@@ -1485,11 +1492,6 @@ static int get_struct_type(var_t *field)
yyerror("field '%s' deriving from a conformant array must be the last field in the structure", yyerror("field '%s' deriving from a conformant array must be the last field in the structure",
field->name); field->name);
break; break;
case RPC_FC_C_CSTRING:
case RPC_FC_C_WSTRING:
has_conformance = 1;
has_variance = 1;
break;
/* /*
* Propagate member attributes * Propagate member attributes
......
...@@ -224,6 +224,12 @@ static void marshall_size_arg( var_t *arg ) ...@@ -224,6 +224,12 @@ static void marshall_size_arg( var_t *arg )
return; return;
} }
if (is_string_type(arg->attrs, arg->ptr_level, arg->array))
{
print_proxy("NdrConformantStringBufferSize( &_StubMsg, (unsigned char*)s, ", arg->name);
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
}
switch( type->type ) switch( type->type )
{ {
case RPC_FC_BYTE: case RPC_FC_BYTE:
...@@ -249,8 +255,6 @@ static void marshall_size_arg( var_t *arg ) ...@@ -249,8 +255,6 @@ static void marshall_size_arg( var_t *arg )
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index ); fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index );
break; break;
case RPC_FC_C_CSTRING:
case RPC_FC_C_WSTRING:
case RPC_FC_CARRAY: case RPC_FC_CARRAY:
print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name ); print_proxy( "NdrConformantArrayBufferSize( &_StubMsg, (unsigned char*)%s, ", arg->name );
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index ); fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
...@@ -323,6 +327,12 @@ static void marshall_copy_arg( var_t *arg ) ...@@ -323,6 +327,12 @@ static void marshall_copy_arg( var_t *arg )
return; return;
} }
if (is_string_type(arg->attrs, arg->ptr_level, arg->array))
{
print_proxy("NdrConformantStringMarshall( &_StubMsg, (unsigned char*)s, ", arg->name);
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d] );\n", index);
}
switch( type->type ) switch( type->type )
{ {
case RPC_FC_BYTE: case RPC_FC_BYTE:
...@@ -348,8 +358,6 @@ static void marshall_copy_arg( var_t *arg ) ...@@ -348,8 +358,6 @@ static void marshall_copy_arg( var_t *arg )
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index ); fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d]);\n", index );
break; break;
case RPC_FC_C_CSTRING:
case RPC_FC_C_WSTRING:
case RPC_FC_CARRAY: case RPC_FC_CARRAY:
break; break;
...@@ -429,6 +437,12 @@ static void unmarshall_copy_arg( var_t *arg ) ...@@ -429,6 +437,12 @@ static void unmarshall_copy_arg( var_t *arg )
return; return;
} }
if (is_string_type(arg->attrs, arg->ptr_level, arg->array))
{
print_proxy("NdrConformantStringUnmarshall( &_StubMsg, (unsigned char**)&s, ", arg->name);
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0 );\n", index);
}
switch( type->type ) switch( type->type )
{ {
case RPC_FC_BYTE: case RPC_FC_BYTE:
...@@ -453,8 +467,6 @@ static void unmarshall_copy_arg( var_t *arg ) ...@@ -453,8 +467,6 @@ static void unmarshall_copy_arg( var_t *arg )
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index ); fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
break; break;
case RPC_FC_C_CSTRING:
case RPC_FC_C_WSTRING:
case RPC_FC_CARRAY: case RPC_FC_CARRAY:
print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name ); print_proxy( "NdrConformantArrayUnmarshall( &_StubMsg, (unsigned char**)&%s, ", arg->name );
fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index ); fprintf(proxy, "&__MIDL_TypeFormatString.Format[%d], 0);\n", index );
......
...@@ -79,9 +79,7 @@ int is_ptr(type_t *t) ...@@ -79,9 +79,7 @@ int is_ptr(type_t *t)
return c == RPC_FC_RP return c == RPC_FC_RP
|| c == RPC_FC_UP || c == RPC_FC_UP
|| c == RPC_FC_FP || c == RPC_FC_FP
|| c == RPC_FC_OP || c == RPC_FC_OP;
|| c == RPC_FC_C_CSTRING
|| c == RPC_FC_C_WSTRING;
} }
/* List of oleauto types that should be recognized by name. /* List of oleauto types that should be recognized by name.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment