typedef struct QStackEntry
{
QObject *value;
+ bool is_list_head;
QTAILQ_ENTRY(QStackEntry) node;
} QStackEntry;
QStackEntry *e = g_malloc0(sizeof(*e));
e->value = value;
+ if (qobject_type(e->value) == QTYPE_QLIST) {
+ e->is_list_head = true;
+ }
QTAILQ_INSERT_HEAD(&qov->stack, e, node);
}
qmp_output_push(qov, list);
}
-static GenericList *qmp_output_next_list(Visitor *v, GenericList **list,
+static GenericList *qmp_output_next_list(Visitor *v, GenericList **listp,
Error **errp)
{
- GenericList *retval = *list;
- *list = retval->next;
- return retval;
+ GenericList *list = *listp;
+ QmpOutputVisitor *qov = to_qov(v);
+ QStackEntry *e = QTAILQ_FIRST(&qov->stack);
+
+ assert(e);
+ if (e->is_list_head) {
+ e->is_list_head = false;
+ return list;
+ }
+
+ return list ? list->next : NULL;
}
static void qmp_output_end_list(Visitor *v, Error **errp)
assert(strings);
while (strings[i++] != NULL);
- if (value >= i - 1) {
+ if (value < 0 || value >= i - 1) {
error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null");
return;
}