Move declarations before statements

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Ján Tomko 2020-08-03 17:27:58 +02:00
parent 908bcaa452
commit a5152f23e7
23 changed files with 68 additions and 47 deletions

View File

@ -171,12 +171,13 @@ bhyveCommandLineToArgv(const char *nativeConfig,
}
for (i = 0; i < line_count; i++) {
curr = lines[i];
size_t j;
char **arglist = NULL;
size_t args_count = 0;
size_t args_alloc = 0;
curr = lines[i];
/* iterate over each line, splitting on sequences of ' '. This code is
* adapted from qemu/qemu_parse_command.c. */
while (curr && *curr != '\0') {

View File

@ -2857,12 +2857,13 @@ void virDomainSoundCodecDefFree(virDomainSoundCodecDefPtr def)
void virDomainSoundDefFree(virDomainSoundDefPtr def)
{
size_t i;
if (!def)
return;
virDomainDeviceInfoClear(&def->info);
size_t i;
for (i = 0; i < def->ncodecs; i++)
virDomainSoundCodecDefFree(def->codecs[i]);
VIR_FREE(def->codecs);
@ -3255,10 +3256,11 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
static void
virDomainClockDefClear(virDomainClockDefPtr def)
{
size_t i;
if (def->offset == VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE)
VIR_FREE(def->data.timezone);
size_t i;
for (i = 0; i < def->ntimers; i++)
VIR_FREE(def->timers[i]);
VIR_FREE(def->timers);
@ -16702,9 +16704,10 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node,
virDomainMemoryDefPtr def)
{
VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node;
g_autofree char *nodemask = NULL;
ctxt->node = node;
switch ((virDomainMemoryModel) def->model) {
case VIR_DOMAIN_MEMORY_MODEL_DIMM:
if (virDomainParseMemory("./pagesize", "./pagesize/@unit", ctxt,

View File

@ -2537,9 +2537,10 @@ virNetworkDefFormatBuf(virBufferPtr buf,
if (def->forward.type != VIR_NETWORK_FORWARD_NONE) {
const char *dev = NULL;
const char *mode = virNetworkForwardTypeToString(def->forward.type);
if (!def->forward.npfs)
dev = virNetworkDefForwardIf(def, 0);
const char *mode = virNetworkForwardTypeToString(def->forward.type);
if (!mode) {
virReportError(VIR_ERR_INTERNAL_ERROR,

View File

@ -1114,9 +1114,10 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr pools,
/* UUID does not match, but if a name matches, refuse it */
obj = virStoragePoolObjFindByNameLocked(pools, def->name);
if (obj) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virObjectLock(obj);
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(obj->def->uuid, uuidstr);
virReportError(VIR_ERR_OPERATION_FAILED,
_("pool '%s' already exists with uuid %s"),

View File

@ -626,12 +626,12 @@ learnIPAddressThread(void *arg)
pcap_close(handle);
if (req->status == 0) {
g_autofree char *inetaddr = NULL;
int ret;
virSocketAddr sa;
sa.len = sizeof(sa.data.inet4);
sa.data.inet4.sin_family = AF_INET;
sa.data.inet4.sin_addr.s_addr = vmaddr;
g_autofree char *inetaddr = NULL;
/* It is necessary to unlock interface here to avoid updateMutex and
* interface ordering deadlocks. Otherwise we are going to

View File

@ -233,16 +233,16 @@ openvzReadNetworkConf(virDomainDefPtr def,
} else if (ret > 0) {
token = strtok_r(temp, ";", &saveptr);
while (token != NULL) {
char *p = token;
char cpy_temp[32];
int len;
/* add new device to list */
if (VIR_ALLOC(net) < 0)
goto error;
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
char *p = token;
char cpy_temp[32];
int len;
/* parse string */
do {
char *next = strchr(p, ',');

View File

@ -523,9 +523,10 @@ qemuProcessShutdownOrReboot(virQEMUDriverPtr driver,
if (priv->fakeReboot) {
g_autofree char *name = g_strdup_printf("reboot-%s", vm->def->name);
virThread th;
qemuDomainSetFakeReboot(driver, vm, false);
virObjectRef(vm);
virThread th;
if (virThreadCreateFull(&th,
false,
qemuProcessFakeReboot,

View File

@ -957,6 +957,7 @@ doRemoteOpen(virConnectPtr conn,
bool tty = true;
#endif
int mode;
size_t i;
if (inside_daemon && !conn->uri->server) {
mode = REMOTE_DRIVER_MODE_DIRECT;
@ -1014,8 +1015,6 @@ doRemoteOpen(virConnectPtr conn,
* feasibly it might contain variables needed by the real driver,
* although that won't be the case for now).
*/
size_t i;
if (conn->uri) {
for (i = 0; i < conn->uri->paramsCount; i++) {
virURIParamPtr var = &conn->uri->params[i];

View File

@ -192,8 +192,8 @@ virStorageBackendCopyToFD(virStorageVolDefPtr vol,
* blocks */
amtleft = amtread;
do {
interval = ((wbytes > amtleft) ? amtleft : wbytes);
int offset = amtread - amtleft;
interval = ((wbytes > amtleft) ? amtleft : wbytes);
if (want_sparse && memcmp(buf+offset, zerobuf, interval) == 0) {
if (lseek(fd, interval, SEEK_CUR) < 0) {

View File

@ -999,6 +999,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
case DBUS_TYPE_SIGNATURE:
do {
char **x;
char *s;
if (arrayref) {
char ***xptrptr = arrayptr;
if (VIR_EXPAND_N(*xptrptr, *narrayptr, 1) < 0)
@ -1008,7 +1009,6 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
} else {
x = (char **)va_arg(args, char **);
}
char *s;
dbus_message_iter_get_basic(iter, &s);
*x = g_strdup(s);
VIR_DEBUG("Read basic type 'char *' varg 'char **'"

View File

@ -94,9 +94,9 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
size_t i;
for (i = 0; i < virJSONValueArraySize(array); i++) {
member = virJSONValueArrayGet((virJSONValuePtr) array, i);
g_autofree char *prefix = NULL;
member = virJSONValueArrayGet((virJSONValuePtr) array, i);
prefix = g_strdup_printf("%s.%zu", key, i);
if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf, skipKey, onOff,

View File

@ -653,6 +653,7 @@ static int
vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
{
vboxDriverPtr data = conn->privateData;
ISystemProperties *systemProperties = NULL;
PRUint32 maxCPUCount = 0;
int ret = -1;
@ -662,7 +663,6 @@ vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type G_GNUC_UNUSED)
/* VirtualBox Supports only hvm and thus the type passed to it
* has no meaning, setting it to G_GNUC_UNUSED
*/
ISystemProperties *systemProperties = NULL;
gVBoxAPI.UIVirtualBox.GetSystemProperties(data->vboxObj, &systemProperties);
if (!systemProperties)
@ -4603,6 +4603,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
char *nameTmpUse = NULL;
bool snapshotFileExists = false;
bool needToChangeStorageController = false;
char uuidtmp[VIR_UUID_STRING_BUFLEN];
int ret = -1;
if (!data->vboxObj)
@ -4782,6 +4783,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
char *parentUuid = NULL;
virVBoxSnapshotConfHardDiskPtr readOnlyDisk = NULL;
vboxIID iid, parentiid;
IMedium *parentReadOnlyMedium = NULL;
VBOX_IID_INITIALIZE(&iid);
VBOX_IID_INITIALIZE(&parentiid);
@ -4831,7 +4833,6 @@ vboxSnapshotRedefine(virDomainPtr dom,
VBOX_UTF16_FREE(formatUtf);
/* This disk is already in the media registry */
IMedium *parentReadOnlyMedium = NULL;
rc = gVBoxAPI.UIMedium.GetParent(readOnlyMedium, &parentReadOnlyMedium);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -4965,7 +4966,6 @@ vboxSnapshotRedefine(virDomainPtr dom,
if (virUUIDGenerate(snapshotUuid) < 0)
goto cleanup;
char uuidtmp[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(snapshotUuid, uuidtmp);
newSnapshotPtr->uuid = g_strdup(uuidtmp);
@ -5176,6 +5176,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
}
}
} else {
char *snapshotContent;
/* Create a "fake" disk to avoid corrupting children snapshot disks. */
for (it = 0; it < def->parent.dom->ndisks; it++) {
IMedium *medium = NULL;
@ -5190,6 +5191,8 @@ vboxSnapshotRedefine(virDomainPtr dom,
char *format = NULL;
char *tmp = NULL;
vboxIID iid, parentiid;
IProgress *progress = NULL;
PRUint32 tab[1];
VBOX_IID_INITIALIZE(&iid);
VBOX_IID_INITIALIZE(&parentiid);
@ -5235,8 +5238,6 @@ vboxSnapshotRedefine(virDomainPtr dom,
goto cleanup;
}
IProgress *progress = NULL;
PRUint32 tab[1];
tab[0] = MediumVariant_Diff;
gVBoxAPI.UIMedium.CreateDiffStorage(medium, newMedium, 1, tab, &progress);
@ -5320,9 +5321,9 @@ vboxSnapshotRedefine(virDomainPtr dom,
VIR_FREE(currentSnapshotXmlFilePath);
currentSnapshotXmlFilePath = g_strdup_printf("%s%s.xml",
machineLocationPath, snapshotMachineDesc->currentSnapshot);
char *snapshotContent = virDomainSnapshotDefFormat(NULL, def,
data->xmlopt,
VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE);
snapshotContent = virDomainSnapshotDefFormat(NULL, def,
data->xmlopt,
VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE);
if (snapshotContent == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to get snapshot content"));
@ -6947,6 +6948,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
char *tmp = NULL;
vboxIID iid, parentiid;
resultCodeUnion resultCode;
PRUint32 tab[1];
VBOX_IID_INITIALIZE(&iid);
VBOX_IID_INITIALIZE(&parentiid);
@ -7004,7 +7006,6 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
VBOX_UTF16_FREE(formatUtf16);
VBOX_UTF16_FREE(newLocation);
PRUint32 tab[1];
tab[0] = MediumVariant_Diff;
gVBoxAPI.UIMedium.CreateDiffStorage(medium, newMedium, 1, tab, &progress);
@ -7536,12 +7537,12 @@ vboxConnectListAllDomains(virConnectPtr conn,
for (i = 0; i < machines.count; i++) {
IMachine *machine = machines.items[i];
PRBool isAccessible = PR_FALSE;
int id = -1;
if (!machine)
continue;
PRBool isAccessible = PR_FALSE;
gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
if (!isAccessible)

View File

@ -1286,8 +1286,10 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(const char *filePath,
for (i = 0; i < nodeSize; i++) {
xmlNodePtr node = nodes[i];
xmlNodePtr sourceNode;
xPathContext->node = node;
xmlNodePtr sourceNode = virXPathNode("./source", xPathContext);
sourceNode = virXPathNode("./source", xPathContext);
if (sourceNode)
ret[i] = virXMLPropString(sourceNode, "file");
}
@ -1347,8 +1349,10 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(const char *filePath,
for (i = 0; i < nodeSize; i++) {
xmlNodePtr node = nodes[i];
xmlNodePtr sourceNode;
xPathContext->node = node;
xmlNodePtr sourceNode = virXPathNode("./source", xPathContext);
sourceNode = virXPathNode("./source", xPathContext);
if (sourceNode)
ret[i] = virXMLPropString(sourceNode, "file");
}

View File

@ -112,6 +112,8 @@ vzBuildCapabilities(void)
};
size_t i, j, k;
G_STATIC_ASSERT(G_N_ELEMENTS(archs) == G_N_ELEMENTS(emulators));
if ((caps = virCapabilitiesNew(virArchFromHost(),
false, false)) == NULL)
return NULL;
@ -122,8 +124,6 @@ vzBuildCapabilities(void)
if (virCapabilitiesInitCaches(caps) < 0)
goto error;
G_STATIC_ASSERT(G_N_ELEMENTS(archs) == G_N_ELEMENTS(emulators));
for (i = 0; i < G_N_ELEMENTS(ostypes); i++)
for (j = 0; j < G_N_ELEMENTS(archs); j++)
for (k = 0; k < G_N_ELEMENTS(emulators); k++)
@ -220,12 +220,12 @@ vzConnectGetCapabilities(virConnectPtr conn)
static int
vzDomainDefAddDefaultInputDevices(virDomainDefPtr def)
{
if (def->ngraphics == 0)
return 0;
int bus = IS_CT(def) ? VIR_DOMAIN_INPUT_BUS_PARALLELS :
VIR_DOMAIN_INPUT_BUS_PS2;
if (def->ngraphics == 0)
return 0;
if (virDomainDefMaybeAddInput(def,
VIR_DOMAIN_INPUT_TYPE_MOUSE,
bus) < 0)

View File

@ -74,6 +74,8 @@ int main(int argc, char **argv) {
char c;
bool daemonize_check = false;
size_t daemonize_retries = 3;
char buf[1024];
ssize_t got;
if (!log)
return ret;
@ -167,9 +169,6 @@ int main(int argc, char **argv) {
usleep(100*1000);
}
char buf[1024];
ssize_t got;
fprintf(stdout, "BEGIN STDOUT\n");
fflush(stdout);
fprintf(stderr, "BEGIN STDERR\n");

View File

@ -89,10 +89,11 @@ G_GNUC_PRINTF(3, 4)
testEventReport(const char *name, bool failed, const char *msg, ...)
{
va_list vargs;
va_start(vargs, msg);
char *str = NULL;
struct testEventResultData data;
va_start(vargs, msg);
if (msg)
str = g_strdup_vprintf(msg, vargs);
@ -325,6 +326,7 @@ mymain(void)
size_t i;
pthread_t eventThread;
char one = '1';
char *debugEnv = getenv("LIBVIRT_DEBUG");
for (i = 0; i < NUM_FDS; i++) {
if (virPipeQuiet(handles[i].pipeFD) < 0) {
@ -333,7 +335,6 @@ mymain(void)
}
}
char *debugEnv = getenv("LIBVIRT_DEBUG");
if (debugEnv && *debugEnv &&
(virLogSetDefaultPriority(virLogParseDefaultPriority(debugEnv)) < 0)) {
fprintf(stderr, "Invalid log level setting.\n");

View File

@ -467,8 +467,10 @@ int access(const char *path, int mode)
init_syms();
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
init_sysfs();
char *newpath;
init_sysfs();
if (asprintf(&newpath, "%s%s",
fakesysfscgroupdir,
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {
@ -534,8 +536,10 @@ int mkdir(const char *path, mode_t mode)
init_syms();
if (STRPREFIX(path, SYSFS_CGROUP_PREFIX)) {
init_sysfs();
char *newpath;
init_sysfs();
if (asprintf(&newpath, "%s%s",
fakesysfscgroupdir,
path + strlen(SYSFS_CGROUP_PREFIX)) < 0) {

View File

@ -3794,8 +3794,10 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
goto error;
for (i = 0; i < nvol_nodes; i++) {
ctxt->node = vol_nodes[i];
virshUndefineVolume vol;
ctxt->node = vol_nodes[i];
VIR_FREE(source);
VIR_FREE(target);
VIR_FREE(pool);

View File

@ -49,9 +49,10 @@ virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
const char *n = NULL;
bool is_mac = false;
virMacAddr dummy;
virCheckFlags(VIRSH_BYNAME | VIRSH_BYMAC, NULL);
virshControlPtr priv = ctl->privData;
virCheckFlags(VIRSH_BYNAME | VIRSH_BYMAC, NULL);
if (!optname)
optname = "interface";

View File

@ -69,9 +69,10 @@ virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
virNetworkPtr network = NULL;
const char *n = NULL;
const char *optname = "network";
virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
virshControlPtr priv = ctl->privData;
virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
return NULL;

View File

@ -285,6 +285,7 @@ virshNodeDeviceListCollect(vshControl *ctl,
char **caps = NULL;
int ncaps = 0;
bool match = false;
size_t j, k;
device = list->devices[i];
@ -305,7 +306,6 @@ virshNodeDeviceListCollect(vshControl *ctl,
/* Check if the device's capability matches with provided
* capabilities.
*/
size_t j, k;
for (j = 0; j < ncaps; j++) {
for (k = 0; k < ncapnames; k++) {
if (STREQ(caps[j], capnames[k])) {

View File

@ -32,9 +32,10 @@ virshLookupDomainInternal(vshControl *ctl,
{
virDomainPtr dom = NULL;
int id;
virCheckFlags(VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME, NULL);
virshControlPtr priv = ctl->privData;
virCheckFlags(VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME, NULL);
/* try it by ID */
if (flags & VIRSH_BYID) {
if (virStrToLong_i(name, NULL, 10, &id) == 0 && id >= 0) {

View File

@ -172,9 +172,10 @@ int virHostValidateNamespace(const char *hvname,
virHostValidateLevel level,
const char *hint)
{
virHostMsgCheck(hvname, "for namespace %s", ns_name);
char nspath[100];
virHostMsgCheck(hvname, "for namespace %s", ns_name);
g_snprintf(nspath, sizeof(nspath), "/proc/self/ns/%s", ns_name);
if (access(nspath, F_OK) < 0) {