On 07/30/2013 09:05 AM, Peter Krempa wrote:
<...snip...>
+/* this allows to add a responder that is able to check
+ * a (shallow) structure of arguments for a command */
+int
+qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
+ const char *cmdname,
+ const char *response,
+ ...)
+{
+ struct qemuMonitorTestHandlerData *data;
+ const char *argname;
+ const char *argval;
+ va_list args;
+
+ va_start(args, response);
+
Coverity complains:
668
(1) Event va_init: Initializing va_list "args".
Also see events: [missing_va_end]
669 va_start(args, response);
670
(2) Event cond_true: Condition "virAlloc(&data, 32UL /* sizeof (*data)
*/, true /* 1 */, VIR_FROM_NONE, "qemumonitortestutils.c", <anonymous>,
671) < 0", taking true branch
671 if (VIR_ALLOC(data) < 0)
(3) Event missing_va_end: va_end was not called for "args".
Also see events: [va_init]
672 return -1;
673
John
+ if (VIR_ALLOC(data) < 0)
+ return -1;
+
+ if (VIR_STRDUP(data->command_name, cmdname) < 0 ||
+ VIR_STRDUP(data->response, response) < 0)
+ goto error;
+
+ while ((argname = va_arg(args, char *))) {
+ size_t i;
+ if (!(argval = va_arg(args, char *))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "Missing argument value for argument
'%s'",
+ argname);
+ goto error;
+ }
+
+ i = data->nargs;
+ if (VIR_EXPAND_N(data->args, data->nargs, 1))
+ goto error;
+
+ if (VIR_STRDUP(data->args[i].argname, argname) < 0 ||
+ VIR_STRDUP(data->args[i].argval, argval) < 0)
+ goto error;
+ }
+
+ va_end(args);
+
+ return qemuMonitorTestAddHandler(test,
+ qemuMonitorTestProcessCommandWithArgs,
+ data, qemuMonitorTestHandlerDataFree);
+
+error:
+ va_end(args);
+ qemuMonitorTestHandlerDataFree(data);
+ return -1;
+}
+
+