scanner: Catch more invalid attribute combinations for arg

Spotted by Jakob Bornecrantz.
This commit is contained in:
Kristian Høgsberg 2011-10-24 16:04:09 -04:00
parent 1ac009473b
commit d63884b0c7
2 changed files with 13 additions and 5 deletions

View file

@ -66,7 +66,7 @@
server will always announce an object before the object sends server will always announce an object before the object sends
out events. --> out events. -->
<event name="global"> <event name="global">
<arg name="name" type="uint" interface="wl_object"/> <arg name="name" type="uint"/>
<arg name="interface" type="string"/> <arg name="interface" type="string"/>
<arg name="version" type="uint"/> <arg name="version" type="uint"/>
</event> </event>

View file

@ -230,19 +230,27 @@ start_element(void *data, const char *element_name, const char **atts)
else if (strcmp(type, "fd") == 0) else if (strcmp(type, "fd") == 0)
arg->type = FD; arg->type = FD;
else if (strcmp(type, "new_id") == 0) { else if (strcmp(type, "new_id") == 0) {
if (interface_name == NULL)
fail(ctx, "no interface name given");
arg->type = NEW_ID; arg->type = NEW_ID;
arg->interface_name = strdup(interface_name); arg->interface_name = strdup(interface_name);
} else if (strcmp(type, "object") == 0) { } else if (strcmp(type, "object") == 0) {
if (interface_name == NULL)
fail(ctx, "no interface name given");
arg->type = OBJECT; arg->type = OBJECT;
arg->interface_name = strdup(interface_name); arg->interface_name = strdup(interface_name);
} else { } else {
fail(ctx, "unknown type"); fail(ctx, "unknown type");
} }
switch (arg->type) {
case NEW_ID:
case OBJECT:
if (interface_name == NULL)
fail(ctx, "no interface name given");
break;
default:
if (interface_name != NULL)
fail(ctx, "interface no allowed");
break;
}
wl_list_insert(ctx->message->arg_list.prev, &arg->link); wl_list_insert(ctx->message->arg_list.prev, &arg->link);
ctx->message->arg_count++; ctx->message->arg_count++;
} else if (strcmp(element_name, "enum") == 0) { } else if (strcmp(element_name, "enum") == 0) {