end = virBitmapLastSetBit(bitmap) + 1;
if (end - 1 > pos) {
- virBufferAsprintf(buf, ",%s=%zd-%zd", key, pos, end - 1);
+ virBufferAsprintf(buf, "%s=%zd-%zd,", key, pos, end - 1);
pos = end;
} else {
- virBufferAsprintf(buf, ",%s=%zd", key, pos);
+ virBufferAsprintf(buf, "%s=%zd,", key, pos);
}
}
switch ((virJSONType) value->type) {
case VIR_JSON_TYPE_STRING:
- virBufferAsprintf(buf, ",%s=", key);
+ virBufferAsprintf(buf, "%s=", key);
virQEMUBuildBufferEscapeComma(buf, value->data.string);
+ virBufferAddLit(buf, ",");
break;
case VIR_JSON_TYPE_NUMBER:
- virBufferAsprintf(buf, ",%s=%s", key, value->data.number);
+ virBufferAsprintf(buf, "%s=%s,", key, value->data.number);
break;
case VIR_JSON_TYPE_BOOLEAN:
if (value->data.boolean)
- virBufferAsprintf(buf, ",%s=yes", key);
+ virBufferAsprintf(buf, "%s=yes,", key);
else
- virBufferAsprintf(buf, ",%s=no", key);
+ virBufferAsprintf(buf, "%s=no,", key);
break;
virBufferPtr buf,
virQEMUBuildCommandLineJSONArrayFormatFunc array)
{
- return virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, array, false);
+ if (virQEMUBuildCommandLineJSONRecurse(NULL, value, buf, array, false) < 0)
+ return -1;
+
+ virBufferTrim(buf, ",", -1);
+
+ return 0;
}
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *ret = NULL;
- virBufferAsprintf(&buf, "%s,id=%s", type, alias);
+ virBufferAsprintf(&buf, "%s,id=%s,", type, alias);
if (virQEMUBuildCommandLineJSON(props, &buf,
virQEMUBuildCommandLineJSONArrayBitmap) < 0)
{
const testQemuCommandBuildObjectFromJSONData *data = opaque;
virJSONValuePtr val = NULL;
- char *expect = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *result = NULL;
int ret = -1;
return -1;
}
- if (data->expectprops &&
- virAsprintf(&expect, ",%s", data->expectprops) < 0)
- return -1;
-
if (virQEMUBuildCommandLineJSON(val, &buf,
virQEMUBuildCommandLineJSONArrayBitmap) < 0) {
fprintf(stderr,
result = virBufferContentAndReset(&buf);
- if (STRNEQ_NULLABLE(expect, result)) {
+ if (STRNEQ_NULLABLE(data->expectprops, result)) {
fprintf(stderr, "\nFailed to create object string. "
"\nExpected:\n'%s'\nGot:\n'%s'",
- NULLSTR(expect), NULLSTR(result));
+ NULLSTR(data->expectprops), NULLSTR(result));
goto cleanup;
}
cleanup:
virJSONValueFree(val);
VIR_FREE(result);
- VIR_FREE(expect);
return ret;
}