提交 f8b42f32 编写于 作者: D Daniel P. Berrange

Convert 'int i' to 'size_t i' in src/util/ files

Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 921d67e0
......@@ -301,7 +301,8 @@ virBitmapParse(const char *str,
bool neg = false;
const char *cur;
char *tmp;
int i, start, last;
size_t i;
int start, last;
if (!str)
return -1;
......@@ -434,7 +435,7 @@ virBitmapPtr virBitmapNewCopy(virBitmapPtr src)
virBitmapPtr virBitmapNewData(void *data, int len)
{
virBitmapPtr bitmap;
int i, j;
size_t i, j;
unsigned long *p;
unsigned char *bytes = data;
......@@ -470,7 +471,7 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen)
{
int len;
unsigned long *l;
int i, j;
size_t i, j;
unsigned char *bytes;
len = (bitmap->max_bit + CHAR_BIT - 1) / CHAR_BIT;
......@@ -507,7 +508,7 @@ int virBitmapToData(virBitmapPtr bitmap, unsigned char **data, int *dataLen)
bool virBitmapEqual(virBitmapPtr b1, virBitmapPtr b2)
{
virBitmapPtr tmp;
int i;
size_t i;
if (b1->max_bit > b2->max_bit) {
tmp = b1;
......@@ -574,7 +575,7 @@ void virBitmapClearAll(virBitmapPtr bitmap)
*/
bool virBitmapIsAllSet(virBitmapPtr bitmap)
{
int i;
size_t i;
int unusedBits;
size_t sz;
......@@ -605,7 +606,7 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap)
*/
bool virBitmapIsAllClear(virBitmapPtr bitmap)
{
int i;
size_t i;
for (i = 0; i < bitmap->map_len; i++)
if (bitmap->map[i] != 0)
......
......@@ -74,7 +74,7 @@ typedef enum {
*/
void virCgroupFree(virCgroupPtr *group)
{
int i;
size_t i;
if (*group == NULL)
return;
......@@ -111,7 +111,7 @@ bool virCgroupHasController(virCgroupPtr cgroup, int controller)
static int virCgroupCopyMounts(virCgroupPtr group,
virCgroupPtr parent)
{
int i;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (!parent->controllers[i].mountPoint)
continue;
......@@ -133,7 +133,7 @@ static int virCgroupCopyMounts(virCgroupPtr group,
*/
static int virCgroupDetectMounts(virCgroupPtr group)
{
int i;
size_t i;
FILE *mounts = NULL;
struct mntent entry;
char buf[CGROUP_MAX_VAL];
......@@ -226,7 +226,7 @@ static int virCgroupCopyPlacement(virCgroupPtr group,
const char *path,
virCgroupPtr parent)
{
int i;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (!group->controllers[i].mountPoint)
continue;
......@@ -279,7 +279,7 @@ static int virCgroupCopyPlacement(virCgroupPtr group,
static int virCgroupDetectPlacement(virCgroupPtr group,
const char *path)
{
int i;
size_t i;
FILE *mapping = NULL;
char line[1024];
......@@ -353,8 +353,8 @@ static int virCgroupDetect(virCgroupPtr group,
virCgroupPtr parent)
{
int rc;
int i;
int j;
size_t i;
size_t j;
VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
group, controllers, path, parent);
......@@ -439,7 +439,7 @@ static int virCgroupDetect(virCgroupPtr group,
break;
}
VIR_DEBUG("Detected mount/mapping %i:%s at %s in %s", i,
VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s", i,
virCgroupControllerTypeToString(i),
group->controllers[i].mountPoint,
group->controllers[i].placement);
......@@ -459,7 +459,7 @@ int virCgroupPathOfController(virCgroupPtr group,
char **path)
{
if (controller == -1) {
int i;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (group->controllers[i].mountPoint &&
group->controllers[i].placement) {
......@@ -630,7 +630,7 @@ out:
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
static int virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group)
{
int i;
size_t i;
int rc = 0;
const char *inherit_values[] = {
"cpuset.cpus",
......@@ -702,7 +702,7 @@ static int virCgroupMakeGroup(virCgroupPtr parent,
bool create,
unsigned int flags)
{
int i;
size_t i;
int rc = 0;
VIR_DEBUG("Make group %s", group->path);
......@@ -938,7 +938,7 @@ int virCgroupRemoveRecursively(char *grppath ATTRIBUTE_UNUSED)
int virCgroupRemove(virCgroupPtr group)
{
int rc = 0;
int i;
size_t i;
char *grppath = NULL;
VIR_DEBUG("Removing cgroup %s", group->path);
......@@ -974,7 +974,7 @@ int virCgroupRemove(virCgroupPtr group)
int virCgroupAddTask(virCgroupPtr group, pid_t pid)
{
int rc = 0;
int i;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
/* Skip over controllers not mounted */
......@@ -1064,7 +1064,7 @@ int virCgroupMoveTask(virCgroupPtr src_group, virCgroupPtr dest_group)
{
int rc = 0;
char *content = NULL;
int i;
size_t i;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
if (!src_group->controllers[i].mountPoint ||
......@@ -2498,7 +2498,7 @@ int virCgroupKillRecursive(virCgroupPtr group, int signum)
int virCgroupKillPainfully(virCgroupPtr group)
{
int i;
size_t i;
int rc;
VIR_DEBUG("cgroup=%p path=%s", group, group->path);
for (i = 0; i < 15; i++) {
......@@ -2511,7 +2511,7 @@ int virCgroupKillPainfully(virCgroupPtr group)
signum = 0; /* Just check for existence */
rc = virCgroupKillRecursive(group, signum);
VIR_DEBUG("Iteration %d rc=%d", i, rc);
VIR_DEBUG("Iteration %zu rc=%d", i, rc);
/* If rc == -1 we hit error, if 0 we ran out of PIDs */
if (rc <= 0)
break;
......
......@@ -139,7 +139,7 @@ virCommandFDIsSet(int fd,
const int *set,
int set_size)
{
int i = 0;
size_t i = 0;
while (i < set_size)
if (set[i++] == fd)
......@@ -259,7 +259,7 @@ virFork(pid_t *pid)
/* child process */
int logprio;
int i;
size_t i;
/* Remove any error callback so errors in child now
get sent to stderr where they stand a fighting chance
......@@ -392,7 +392,7 @@ static int
virExec(virCommandPtr cmd)
{
pid_t pid;
int null = -1, i, openmax;
int null = -1, fd, openmax;
int pipeout[2] = {-1,-1};
int pipeerr[2] = {-1,-1};
int childin = cmd->infd;
......@@ -511,15 +511,15 @@ virExec(virCommandPtr cmd)
}
openmax = sysconf(_SC_OPEN_MAX);
for (i = 3; i < openmax; i++) {
if (i == childin || i == childout || i == childerr)
for (fd = 3; fd < openmax; fd++) {
if (fd == childin || fd == childout || fd == childerr)
continue;
if (!cmd->preserve ||
!virCommandFDIsSet(i, cmd->preserve, cmd->preserve_size)) {
tmpfd = i;
!virCommandFDIsSet(fd, cmd->preserve, cmd->preserve_size)) {
tmpfd = fd;
VIR_MASS_CLOSE(tmpfd);
} else if (virSetInherit(i, true) < 0) {
virReportSystemError(errno, _("failed to preserve fd %d"), i);
} else if (virSetInherit(fd, true) < 0) {
virReportSystemError(errno, _("failed to preserve fd %d"), fd);
goto fork_error;
}
}
......@@ -1853,7 +1853,7 @@ virCommandProcessIO(virCommandPtr cmd)
ret = -1;
for (;;) {
int i;
size_t i;
struct pollfd fds[3];
int nfds = 0;
......@@ -2170,7 +2170,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
{
int ret = -1;
char *str;
int i;
size_t i;
bool synchronous = false;
int infd[2] = {-1, -1};
......@@ -2538,7 +2538,7 @@ int virCommandHandshakeNotify(virCommandPtr cmd)
void
virCommandFree(virCommandPtr cmd)
{
int i;
size_t i;
if (!cmd)
return;
......
......@@ -64,7 +64,7 @@ dhcphostFree(dnsmasqDhcpHost *host)
static void
addnhostFree(dnsmasqAddnHost *host)
{
int i;
size_t i;
for (i = 0; i < host->nhostnames; i++)
VIR_FREE(host->hostnames[i]);
......@@ -75,7 +75,7 @@ addnhostFree(dnsmasqAddnHost *host)
static void
addnhostsFree(dnsmasqAddnHostsfile *addnhostsfile)
{
unsigned int i;
size_t i;
if (addnhostsfile->hosts) {
for (i = 0; i < addnhostsfile->nhosts; i++)
......@@ -98,7 +98,7 @@ addnhostsAdd(dnsmasqAddnHostsfile *addnhostsfile,
{
char *ipstr = NULL;
int idx = -1;
int i;
size_t i;
if (!(ipstr = virSocketAddrFormat(ip)))
return -1;
......@@ -174,7 +174,7 @@ addnhostsWrite(const char *path,
char *tmp;
FILE *f;
bool istmp = true;
unsigned int i, ii;
size_t i, j;
int rc = 0;
/* even if there are 0 hosts, create a 0 length file, to allow
......@@ -203,8 +203,8 @@ addnhostsWrite(const char *path,
goto cleanup;
}
for (ii = 0; ii < hosts[i].nhostnames; ii++) {
if (fputs(hosts[i].hostnames[ii], f) == EOF || fputc('\t', f) == EOF) {
for (j = 0; j < hosts[i].nhostnames; j++) {
if (fputs(hosts[i].hostnames[j], f) == EOF || fputc('\t', f) == EOF) {
rc = -errno;
VIR_FORCE_FCLOSE(f);
......@@ -276,7 +276,7 @@ genericFileDelete(char *path)
static void
hostsfileFree(dnsmasqHostsfile *hostsfile)
{
unsigned int i;
size_t i;
if (hostsfile->hosts) {
for (i = 0; i < hostsfile->nhosts; i++)
......@@ -380,7 +380,7 @@ hostsfileWrite(const char *path,
char *tmp;
FILE *f;
bool istmp = true;
unsigned int i;
size_t i;
int rc = 0;
/* even if there are 0 hosts, create a 0 length file, to allow
......
......@@ -106,7 +106,7 @@ ebtRuleFree(ebtRule *rule)
VIR_FREE(rule->rule);
if (rule->argv) {
int i = 0;
size_t i = 0;
while (rule->argv[i])
VIR_FREE(rule->argv[i++]);
VIR_FREE(rule->argv);
......@@ -120,7 +120,7 @@ ebtRulesAppend(ebtRules *rules,
int command_idx)
{
if (VIR_REALLOC_N(rules->rules, rules->nrules+1) < 0) {
int i = 0;
size_t i = 0;
while (argv[i])
VIR_FREE(argv[i++]);
VIR_FREE(argv);
......@@ -140,7 +140,7 @@ static int
ebtRulesRemove(ebtRules *rules,
char *rule)
{
int i;
size_t i;
for (i = 0; i < rules->nrules; i++)
if (STREQ(rules->rules[i].rule, rule))
......@@ -163,7 +163,7 @@ ebtRulesRemove(ebtRules *rules,
static void
ebtRulesFree(ebtRules *rules)
{
int i;
size_t i;
VIR_FREE(rules->table);
VIR_FREE(rules->chain);
......
......@@ -140,7 +140,7 @@ int virEventPollAddHandle(int fd, int events,
}
void virEventPollUpdateHandle(int watch, int events) {
int i;
size_t i;
bool found = false;
PROBE(EVENT_POLL_UPDATE_HANDLE,
"watch=%d events=%d",
......@@ -174,7 +174,7 @@ void virEventPollUpdateHandle(int watch, int events) {
* Actual deletion will be done out-of-band
*/
int virEventPollRemoveHandle(int watch) {
int i;
size_t i;
PROBE(EVENT_POLL_REMOVE_HANDLE,
"watch=%d",
watch);
......@@ -190,7 +190,7 @@ int virEventPollRemoveHandle(int watch) {
continue;
if (eventLoop.handles[i].watch == watch) {
EVENT_DEBUG("mark delete %d %d", i, eventLoop.handles[i].fd);
EVENT_DEBUG("mark delete %zu %d", i, eventLoop.handles[i].fd);
eventLoop.handles[i].deleted = 1;
virEventPollInterruptLocked();
virMutexUnlock(&eventLoop.lock);
......@@ -253,7 +253,7 @@ int virEventPollAddTimeout(int frequency,
void virEventPollUpdateTimeout(int timer, int frequency)
{
unsigned long long now;
int i;
size_t i;
bool found = false;
PROBE(EVENT_POLL_UPDATE_TIMEOUT,
"timer=%d frequency=%d",
......@@ -294,7 +294,7 @@ void virEventPollUpdateTimeout(int timer, int frequency)
* Actual deletion will be done out-of-band
*/
int virEventPollRemoveTimeout(int timer) {
int i;
size_t i;
PROBE(EVENT_POLL_REMOVE_TIMEOUT,
"timer=%d",
timer);
......@@ -328,7 +328,7 @@ int virEventPollRemoveTimeout(int timer) {
*/
static int virEventPollCalculateTimeout(int *timeout) {
unsigned long long then = 0;
int i;
size_t i;
EVENT_DEBUG("Calculate expiry of %zu timers", eventLoop.timeoutsCount);
/* Figure out if we need a timeout */
for (i = 0; i < eventLoop.timeoutsCount; i++) {
......@@ -370,7 +370,7 @@ static int virEventPollCalculateTimeout(int *timeout) {
*/
static struct pollfd *virEventPollMakePollFDs(int *nfds) {
struct pollfd *fds;
int i;
size_t i;
*nfds = 0;
for (i = 0; i < eventLoop.handlesCount; i++) {
......@@ -384,7 +384,7 @@ static struct pollfd *virEventPollMakePollFDs(int *nfds) {
*nfds = 0;
for (i = 0; i < eventLoop.handlesCount; i++) {
EVENT_DEBUG("Prepare n=%d w=%d, f=%d e=%d d=%d", i,
EVENT_DEBUG("Prepare n=%zu w=%d, f=%d e=%d d=%d", i,
eventLoop.handles[i].watch,
eventLoop.handles[i].fd,
eventLoop.handles[i].events,
......@@ -417,7 +417,7 @@ static struct pollfd *virEventPollMakePollFDs(int *nfds) {
static int virEventPollDispatchTimeouts(void)
{
unsigned long long now;
int i;
size_t i;
/* Save this now - it may be changed during dispatch */
int ntimeouts = eventLoop.timeoutsCount;
VIR_DEBUG("Dispatch %d", ntimeouts);
......@@ -464,7 +464,7 @@ static int virEventPollDispatchTimeouts(void)
* Returns 0 upon success, -1 if an error occurred
*/
static int virEventPollDispatchHandles(int nfds, struct pollfd *fds) {
int i, n;
size_t i, n;
VIR_DEBUG("Dispatch %d", nfds);
/* NB, use nfds not eventLoop.handlesCount, because new
......@@ -479,9 +479,9 @@ static int virEventPollDispatchHandles(int nfds, struct pollfd *fds) {
if (i == eventLoop.handlesCount)
break;
VIR_DEBUG("i=%d w=%d", i, eventLoop.handles[i].watch);
VIR_DEBUG("i=%zu w=%d", i, eventLoop.handles[i].watch);
if (eventLoop.handles[i].deleted) {
EVENT_DEBUG("Skip deleted n=%d w=%d f=%d", i,
EVENT_DEBUG("Skip deleted n=%zu w=%d f=%d", i,
eventLoop.handles[i].watch, eventLoop.handles[i].fd);
continue;
}
......@@ -509,7 +509,7 @@ static int virEventPollDispatchHandles(int nfds, struct pollfd *fds) {
* cleanup is needed to make dispatch re-entrant safe.
*/
static void virEventPollCleanupTimeouts(void) {
int i;
size_t i;
size_t gap;
VIR_DEBUG("Cleanup %zu", eventLoop.timeoutsCount);
......@@ -557,7 +557,7 @@ static void virEventPollCleanupTimeouts(void) {
* cleanup is needed to make dispatch re-entrant safe.
*/
static void virEventPollCleanupHandles(void) {
int i;
size_t i;
size_t gap;
VIR_DEBUG("Cleanup %zu", eventLoop.handlesCount);
......
......@@ -139,7 +139,8 @@ virHookCheck(int no, const char *driver) {
*/
int
virHookInitialize(void) {
int i, res, ret = 0;
size_t i;
int res, ret = 0;
virHooksFound = 0;
for (i = 0; i < VIR_HOOK_DRIVER_LAST; i++) {
......
......@@ -64,7 +64,7 @@ struct _virJSONParser {
void virJSONValueFree(virJSONValuePtr value)
{
int i;
size_t i;
if (!value || value->protect)
return;
......@@ -401,7 +401,7 @@ int virJSONValueArrayAppend(virJSONValuePtr array, virJSONValuePtr value)
int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key)
{
int i;
size_t i;
if (object->type != VIR_JSON_TYPE_OBJECT)
return -1;
......@@ -416,7 +416,7 @@ int virJSONValueObjectHasKey(virJSONValuePtr object, const char *key)
virJSONValuePtr virJSONValueObjectGet(virJSONValuePtr object, const char *key)
{
int i;
size_t i;
if (object->type != VIR_JSON_TYPE_OBJECT)
return NULL;
......@@ -455,7 +455,7 @@ int
virJSONValueObjectRemoveKey(virJSONValuePtr object, const char *key,
virJSONValuePtr *value)
{
int i;
size_t i;
if (value)
*value = NULL;
......@@ -1011,7 +1011,7 @@ cleanup:
yajl_free(hand);
if (parser.nstate) {
int i;
size_t i;
for (i = 0; i < parser.nstate; i++) {
VIR_FREE(parser.state[i].key);
}
......@@ -1026,7 +1026,7 @@ cleanup:
static int virJSONValueToStringOne(virJSONValuePtr object,
yajl_gen g)
{
int i;
size_t i;
VIR_DEBUG("object=%p type=%d gen=%p", object, object->type, g);
......
......@@ -90,7 +90,7 @@ VIR_ENUM_IMPL(virKeycodeSet, VIR_KEYCODE_SET_LAST,
int virKeycodeValueFromString(virKeycodeSet codeset,
const char *keyname)
{
int i;
size_t i;
for (i = 0; i < VIR_KEYMAP_ENTRY_MAX; i++) {
if (!virKeymapNames[codeset] ||
......@@ -111,7 +111,7 @@ int virKeycodeValueTranslate(virKeycodeSet from_codeset,
virKeycodeSet to_codeset,
int key_value)
{
int i;
size_t i;
if (key_value <= 0)
return -1;
......
......@@ -366,7 +366,7 @@ virLogStr(const char *str)
static void
virLogDumpAllFD(const char *msg, int len)
{
int i;
size_t i;
bool found = false;
if (len <= 0)
......@@ -513,7 +513,7 @@ virLogSetDefaultPriority(virLogPriority priority)
static int
virLogResetFilters(void)
{
int i;
size_t i;
for (i = 0; i < virLogNbFilters; i++)
VIR_FREE(virLogFilters[i].match);
......@@ -541,7 +541,8 @@ virLogDefineFilter(const char *match,
virLogPriority priority,
unsigned int flags)
{
int i;
size_t i;
int ret = -1;
char *mdup = NULL;
virCheckFlags(VIR_LOG_STACK_TRACE, -1);
......@@ -554,29 +555,27 @@ virLogDefineFilter(const char *match,
for (i = 0; i < virLogNbFilters; i++) {
if (STREQ(virLogFilters[i].match, match)) {
virLogFilters[i].priority = priority;
ret = i;
goto cleanup;
}
}
if (VIR_STRDUP_QUIET(mdup, match) < 0) {
i = -1;
if (VIR_STRDUP_QUIET(mdup, match) < 0)
goto cleanup;
}
i = virLogNbFilters;
if (VIR_REALLOC_N_QUIET(virLogFilters, virLogNbFilters + 1)) {
i = -1;
VIR_FREE(mdup);
goto cleanup;
}
ret = virLogNbFilters;
virLogFilters[i].match = mdup;
virLogFilters[i].priority = priority;
virLogFilters[i].flags = flags;
virLogNbFilters++;
cleanup:
virLogUnlock();
if (i < 0)
if (ret < 0)
virReportOOMError();
return i;
return ret;
}
......@@ -595,7 +594,7 @@ virLogFiltersCheck(const char *input,
unsigned int *flags)
{
int ret = 0;
int i;
size_t i;
virLogLock();
for (i = 0; i < virLogNbFilters; i++) {
......@@ -620,7 +619,7 @@ virLogFiltersCheck(const char *input,
static int
virLogResetOutputs(void)
{
int i;
size_t i;
for (i = 0; i < virLogNbOutputs; i++) {
if (virLogOutputs[i].c != NULL)
......@@ -805,7 +804,8 @@ virLogVMessage(virLogSource source,
char *str = NULL;
char *msg = NULL;
char timestamp[VIR_TIME_STRING_BUFLEN];
int fprio, i, ret;
int fprio, ret;
size_t i;
int saved_errno = errno;
bool emit = true;
unsigned int filterflags = 0;
......@@ -1486,7 +1486,7 @@ virLogGetDefaultPriority(void)
char *
virLogGetFilters(void)
{
int i;
size_t i;
virBuffer filterbuf = VIR_BUFFER_INITIALIZER;
virLogLock();
......@@ -1520,7 +1520,7 @@ virLogGetFilters(void)
char *
virLogGetOutputs(void)
{
int i;
size_t i;
virBuffer outputbuf = VIR_BUFFER_INITIALIZER;
virLogLock();
......
......@@ -97,7 +97,7 @@ static inline void virLogEatParams(virLogSource unused, ...)
struct _virLogMetadata {
const char *key;
const char *s; /* String value, or NULL to use "i" */
int i;
int iv;
};
typedef struct _virLogMetadata virLogMetadata;
......
......@@ -146,7 +146,7 @@ virMacAddrGetRaw(virMacAddrPtr src, unsigned char dst[VIR_MAC_BUFLEN])
int
virMacAddrParse(const char* str, virMacAddrPtr addr)
{
int i;
size_t i;
errno = 0;
for (i = 0; i < VIR_MAC_BUFLEN; i++) {
......
......@@ -1078,7 +1078,8 @@ virNetDevGetVirtualFunctions(const char *pfname,
virPCIDeviceAddressPtr **virt_fns,
unsigned int *n_vfname)
{
int ret = -1, i;
int ret = -1;
size_t i;
char *pf_sysfs_device_link = NULL;
char *pci_sysfs_device_link = NULL;
char *pciConfigAddr = NULL;
......
......@@ -511,14 +511,14 @@ int virNetDevBridgeGetSTPDelay(const char *brname,
int fd = -1;
int ret = -1;
struct ifreq ifr;
unsigned long i;
unsigned long val;
if ((fd = virNetDevSetupControl(brname, &ifr)) < 0)
goto cleanup;
ret = virNetDevBridgeGet(brname, "forward_delay", &i,
ret = virNetDevBridgeGet(brname, "forward_delay", &val,
fd, &ifr);
*delayms = JIFFIES_TO_MS(i);
*delayms = JIFFIES_TO_MS(val);
cleanup:
VIR_FORCE_CLOSE(fd);
......@@ -571,14 +571,14 @@ int virNetDevBridgeGetSTP(const char *brname,
int fd = -1;
int ret = -1;
struct ifreq ifr;
unsigned long i;
unsigned long val;
if ((fd = virNetDevSetupControl(brname, &ifr)) < 0)
goto cleanup;
ret = virNetDevBridgeGet(brname, "stp_state", &i,
ret = virNetDevBridgeGet(brname, "stp_state", &val,
fd, &ifr);
*enabled = i ? true : false;
*enabled = val ? true : false;
cleanup:
VIR_FORCE_CLOSE(fd);
......
......@@ -596,7 +596,7 @@ virNetDevMacVLanVPortProfileCallback(struct nlmsghdr *hdr,
if (virMacAddrCmpRaw(&calld->macaddress, mac->mac))
{
/* Repeat the same check for a broadcast mac */
int i;
size_t i;
for (i = 0; i < VIR_MAC_BUFLEN; i++) {
if (calld->macaddress.addr[i] != 0xff) {
......
......@@ -51,7 +51,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
virNetDevVlanPtr virtVlan)
{
int ret = -1;
int i = 0;
size_t i = 0;
virCommandPtr cmd = NULL;
char macaddrstr[VIR_MAC_STRING_BUFLEN];
char ifuuidstr[VIR_UUID_STRING_BUFLEN];
......
......@@ -156,7 +156,7 @@ int virNetDevTapCreate(char **ifname,
int tapfdSize,
unsigned int flags)
{
int i;
size_t i;
struct ifreq ifr;
int ret = -1;
int fd;
......@@ -311,7 +311,7 @@ int virNetDevTapCreate(char **ifname,
* matches this pattern
*/
if (strstr(*ifname, "%d") != NULL) {
int i;
size_t i;
for (i = 0; i <= IF_MAXUNIT; i++) {
char *newname;
if (virAsprintf(&newname, *ifname, i) < 0)
......
......@@ -781,7 +781,7 @@ virNetDevVPortProfileGetNthParent(const char *ifname, int ifindex, unsigned int
int rc;
struct nlattr *tb[IFLA_MAX + 1] = { NULL, };
bool end = false;
unsigned int i = 0;
size_t i = 0;
*nth = 0;
......
......@@ -326,7 +326,8 @@ virNetlinkEventCallback(int watch,
struct nlmsghdr *msg;
struct sockaddr_nl peer;
struct ucred *creds = NULL;
int i, length;
size_t i;
int length;
bool handled = false;
length = nl_recv(srv->netlinknh, &peer,
......@@ -349,7 +350,7 @@ virNetlinkEventCallback(int watch,
if (srv->handles[i].deleted != VIR_NETLINK_HANDLE_VALID)
continue;
VIR_DEBUG("dispatching client %d.", i);
VIR_DEBUG("dispatching client %zu.", i);
(srv->handles[i].handleCB)(msg, length, &peer, &handled,
srv->handles[i].opaque);
......@@ -378,7 +379,7 @@ virNetlinkEventServiceStop(unsigned int protocol)
return -EINVAL;
virNetlinkEventSrvPrivatePtr srv = server[protocol];
int i;
size_t i;
VIR_INFO("stopping netlink event service");
......@@ -414,7 +415,7 @@ virNetlinkEventServiceStop(unsigned int protocol)
int
virNetlinkEventServiceStopAll(void)
{
unsigned int i, j;
size_t i, j;
virNetlinkEventSrvPrivatePtr srv = NULL;
VIR_INFO("stopping all netlink event services");
......@@ -612,7 +613,8 @@ virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
void *opaque, const virMacAddrPtr macaddr,
unsigned int protocol)
{
int i, r, ret = -1;
size_t i;
int r, ret = -1;
virNetlinkEventSrvPrivatePtr srv = NULL;
if (protocol >= MAX_LINKS)
......@@ -685,7 +687,7 @@ int
virNetlinkEventRemoveClient(int watch, const virMacAddrPtr macaddr,
unsigned int protocol)
{
int i;
size_t i;
int ret = -1;
virNetlinkEventSrvPrivatePtr srv = NULL;
......
......@@ -87,7 +87,8 @@ virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
int mode = -1;
int node = -1;
int ret = -1;
int i = 0;
int bit = 0;
size_t i;
int maxnode = 0;
virBitmapPtr tmp_nodemask = NULL;
......@@ -115,15 +116,15 @@ virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
/* Convert nodemask to NUMA bitmask. */
nodemask_zero(&mask);
i = -1;
while ((i = virBitmapNextSetBit(tmp_nodemask, i)) >= 0) {
if (i > maxnode || i > NUMA_NUM_NODES) {
bit = -1;
while ((bit = virBitmapNextSetBit(tmp_nodemask, bit)) >= 0) {
if (bit > maxnode || bit > NUMA_NUM_NODES) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Nodeset is out of range, host cannot support "
"NUMA node bigger than %d"), i);
"NUMA node bigger than %d"), bit);
return -1;
}
nodemask_set(&mask, i);
nodemask_set(&mask, bit);
}
mode = numatune.memory.mode;
......
......@@ -1649,7 +1649,7 @@ static void
virPCIDeviceListDispose(void *obj)
{
virPCIDeviceListPtr list = obj;
int i;
size_t i;
for (i = 0; i < list->count; i++) {
virPCIDeviceFree(list->devs[i]);
......@@ -1755,7 +1755,7 @@ virPCIDeviceListDel(virPCIDeviceListPtr list,
int
virPCIDeviceListFindIndex(virPCIDeviceListPtr list, virPCIDevicePtr dev)
{
int i;
size_t i;
for (i = 0; i < list->count; i++)
if (list->devs[i]->domain == dev->domain &&
......@@ -1774,7 +1774,7 @@ virPCIDeviceListFindByIDs(virPCIDeviceListPtr list,
unsigned int slot,
unsigned int function)
{
int i;
size_t i;
for (i = 0; i < list->count; i++) {
if (list->devs[i]->domain == domain &&
......@@ -1790,10 +1790,10 @@ virPCIDeviceListFindByIDs(virPCIDeviceListPtr list,
virPCIDevicePtr
virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDevicePtr dev)
{
int i;
int idx;
if ((i = virPCIDeviceListFindIndex(list, dev)) >= 0)
return list->devs[i];
if ((idx = virPCIDeviceListFindIndex(list, dev)) >= 0)
return list->devs[idx];
else
return NULL;
}
......@@ -2377,7 +2377,7 @@ virPCIGetVirtualFunctions(const char *sysfs_path,
unsigned int *num_virtual_functions)
{
int ret = -1;
int i;
size_t i;
DIR *dir = NULL;
struct dirent *entry = NULL;
char *device_link = NULL;
......@@ -2476,7 +2476,8 @@ virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
const char *vf_sysfs_device_link,
int *vf_index)
{
int ret = -1, i;
int ret = -1;
size_t i;
unsigned int num_virt_fns = 0;
virPCIDeviceAddressPtr vf_bdf = NULL;
virPCIDeviceAddressPtr *virt_fns = NULL;
......
......@@ -97,7 +97,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
unsigned short *port)
{
int ret = -1;
int i;
size_t i;
int fd = -1;
*port = 0;
......@@ -111,7 +111,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
if (virBitmapGetBit(pa->bitmap,
i - pa->start, &used) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to query port %d"), i);
_("Failed to query port %zu"), i);
goto cleanup;
}
......@@ -137,7 +137,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
if (errno != EADDRINUSE) {
virReportSystemError(errno,
_("Unable to bind to port %d"), i);
_("Unable to bind to port %zu"), i);
goto cleanup;
}
/* In use, try next */
......@@ -147,7 +147,7 @@ int virPortAllocatorAcquire(virPortAllocatorPtr pa,
if (virBitmapSetBit(pa->bitmap,
i - pa->start) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to reserve port %d"), i);
_("Failed to reserve port %zu"), i);
goto cleanup;
}
*port = i;
......
......@@ -262,7 +262,8 @@ int virProcessKill(pid_t pid, int sig)
int
virProcessKillPainfully(pid_t pid, bool force)
{
int i, ret = -1;
size_t i;
int ret = -1;
const char *signame = "TERM";
VIR_DEBUG("vpid=%lld force=%d", (long long)pid, force);
......@@ -322,7 +323,7 @@ cleanup:
int virProcessSetAffinity(pid_t pid, virBitmapPtr map)
{
int i;
size_t i;
bool set = false;
# ifdef CPU_ALLOC
/* New method dynamically allocates cpu mask, allowing unlimted cpus */
......@@ -392,7 +393,7 @@ int virProcessGetAffinity(pid_t pid,
virBitmapPtr *map,
int maxcpu)
{
int i;
size_t i;
# ifdef CPU_ALLOC
/* New method dynamically allocates cpu mask, allowing unlimted cpus */
int numcpus = 1024;
......
......@@ -340,7 +340,7 @@ static void
virSCSIDeviceListDispose(void *obj)
{
virSCSIDeviceListPtr list = obj;
int i;
size_t i;
for (i = 0; i < list->count; i++)
virSCSIDeviceFree(list->devs[i]);
......@@ -387,7 +387,7 @@ virSCSIDeviceListSteal(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev)
{
virSCSIDevicePtr ret = NULL;
int i;
size_t i;
for (i = 0; i < list->count; i++) {
if (list->devs[i]->adapter != dev->adapter ||
......@@ -425,7 +425,7 @@ virSCSIDevicePtr
virSCSIDeviceListFind(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev)
{
int i;
size_t i;
for (i = 0; i < list->count; i++) {
if (list->devs[i]->adapter == dev->adapter &&
......
......@@ -42,7 +42,7 @@ typedef virSocketAddrIPv6 *virSocketAddrIPv6Ptr;
static int virSocketAddrGetIPv4Addr(virSocketAddrPtr addr, virSocketAddrIPv4Ptr tab) {
unsigned long val;
int i;
size_t i;
if ((addr == NULL) || (tab == NULL) || (addr->data.stor.ss_family != AF_INET))
return -1;
......@@ -58,7 +58,7 @@ static int virSocketAddrGetIPv4Addr(virSocketAddrPtr addr, virSocketAddrIPv4Ptr
}
static int virSocketAddrGetIPv6Addr(virSocketAddrPtr addr, virSocketAddrIPv6Ptr tab) {
int i;
size_t i;
if ((addr == NULL) || (tab == NULL) || (addr->data.stor.ss_family != AF_INET6))
return -1;
......@@ -418,11 +418,11 @@ virSocketAddrMask(const virSocketAddrPtr addr,
return 0;
}
if (addr->data.stor.ss_family == AF_INET6) {
int ii;
for (ii = 0; ii < 16; ii++) {
network->data.inet6.sin6_addr.s6_addr[ii]
= (addr->data.inet6.sin6_addr.s6_addr[ii]
& netmask->data.inet6.sin6_addr.s6_addr[ii]);
size_t i;
for (i = 0; i < 16; i++) {
network->data.inet6.sin6_addr.s6_addr[i]
= (addr->data.inet6.sin6_addr.s6_addr[i]
& netmask->data.inet6.sin6_addr.s6_addr[i]);
}
network->data.inet6.sin6_port = 0;
network->data.stor.ss_family = AF_INET6;
......@@ -529,7 +529,7 @@ virSocketAddrBroadcastByPrefix(const virSocketAddrPtr addr,
*/
int virSocketAddrCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2,
virSocketAddrPtr netmask) {
int i;
size_t i;
if ((addr1 == NULL) || (addr2 == NULL) || (netmask == NULL))
return -1;
......@@ -585,7 +585,8 @@ int virSocketAddrCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2,
* Returns the size of the range or -1 in case of failure
*/
int virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
int ret = 0, i;
int ret = 0;
size_t i;
if ((start == NULL) || (end == NULL))
return -1;
......@@ -640,7 +641,7 @@ int virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end) {
*/
int virSocketAddrGetNumNetmaskBits(const virSocketAddrPtr netmask)
{
int i, j;
size_t i, j;
int c = 0;
if (netmask->data.stor.ss_family == AF_INET) {
......@@ -748,24 +749,24 @@ virSocketAddrPrefixToNetmask(unsigned int prefix,
result = 0;
} else if (family == AF_INET6) {
int ii = 0;
size_t i = 0;
if (prefix > 128)
goto error;
while (prefix >= 8) {
/* do as much as possible an entire byte at a time */
netmask->data.inet6.sin6_addr.s6_addr[ii++] = 0xff;
netmask->data.inet6.sin6_addr.s6_addr[i++] = 0xff;
prefix -= 8;
}
if (prefix > 0) {
/* final partial byte */
netmask->data.inet6.sin6_addr.s6_addr[ii++]
netmask->data.inet6.sin6_addr.s6_addr[i++]
= ~((1 << (8 - prefix)) -1);
}
while (ii < 16) {
while (i < 16) {
/* zerofill remainder in case it wasn't initialized */
netmask->data.inet6.sin6_addr.s6_addr[ii++] = 0;
netmask->data.inet6.sin6_addr.s6_addr[i++] = 0;
}
netmask->data.stor.ss_family = AF_INET6;
result = 0;
......
......@@ -630,7 +630,8 @@ virStorageFileMatchesVersion(int format,
unsigned char *buf,
size_t buflen)
{
int version, i;
int version;
size_t i;
/* Validate version number info */
if (fileTypeInfo[format].versionOffset == -1)
......@@ -675,7 +676,7 @@ virStorageFileProbeFormatFromBuf(const char *path,
size_t buflen)
{
int format = VIR_STORAGE_FILE_RAW;
int i;
size_t i;
int possibleFormat = VIR_STORAGE_FILE_RAW;
VIR_DEBUG("path=%s", path);
......@@ -719,7 +720,7 @@ qcow2GetFeatures(virBitmapPtr *features,
int version = -1;
virBitmapPtr feat = NULL;
uint64_t bits;
int i;
size_t i;
version = virReadBufInt32BE(buf + fileTypeInfo[format].versionOffset);
......
......@@ -494,7 +494,8 @@ virSkipSpacesBackwards(const char *str, char **endp)
char *
virArgvToString(const char *const *argv)
{
int len, i;
int len;
size_t i;
char *ret, *p;
for (len = 1, i = 0; argv[i]; i++)
......
......@@ -73,7 +73,7 @@ void virSysinfoSetup(const char *dmidecode, const char *sysinfo,
void virSysinfoDefFree(virSysinfoDefPtr def)
{
int i;
size_t i;
if (def == NULL)
return;
......@@ -920,7 +920,7 @@ virSysinfoSystemFormat(virBufferPtr buf, virSysinfoDefPtr def)
static void
virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def)
{
int i;
size_t i;
virSysinfoProcessorDefPtr processor;
for (i = 0; i < def->nprocessor; i++) {
......@@ -972,7 +972,7 @@ virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def)
static void
virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def)
{
int i;
size_t i;
virSysinfoMemoryDefPtr memory;
for (i = 0; i < def->nmemory; i++) {
......
......@@ -33,7 +33,7 @@ typedef struct virThreadLocalData virThreadLocalData;
typedef virThreadLocalData *virThreadLocalDataPtr;
virMutex virThreadLocalLock;
unsigned int virThreadLocalCount = 0;
size_t virThreadLocalCount = 0;
virThreadLocalDataPtr virThreadLocalList = NULL;
DWORD selfkey;
......@@ -54,7 +54,7 @@ int virThreadInitialize(void)
void virThreadOnExit(void)
{
unsigned int i;
size_t i;
virMutexLock(&virThreadLocalLock);
for (i = 0; i < virThreadLocalCount; i++) {
if (virThreadLocalList[i].cleanup) {
......@@ -219,7 +219,7 @@ void virCondBroadcast(virCondPtr c)
virMutexLock(&c->lock);
if (c->nwaiters) {
unsigned int i;
size_t i;
for (i = 0; i < c->nwaiters; i++) {
HANDLE event = c->waiters[i];
SetEvent(event);
......
......@@ -32,7 +32,7 @@ struct virMutex {
struct virCond {
virMutex lock;
unsigned int nwaiters;
size_t nwaiters;
HANDLE *waiters;
};
......
......@@ -51,7 +51,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
{
va_list ap;
int ret = -1;
int i, j;
size_t i, j;
const char *name;
int type;
......@@ -117,7 +117,7 @@ virTypedParamsCheck(virTypedParameterPtr params,
const char **names,
int nnames)
{
int i, j;
size_t i, j;
for (i = 0; i < nparams; i++) {
bool found = false;
......@@ -388,7 +388,7 @@ virTypedParamsCopy(virTypedParameterPtr *dst,
virTypedParameterPtr src,
int nparams)
{
int i;
size_t i;
*dst = NULL;
if (!src || nparams <= 0)
......@@ -432,7 +432,7 @@ virTypedParamsGet(virTypedParameterPtr params,
int nparams,
const char *name)
{
int i;
size_t i;
virResetLastError();
......@@ -1133,7 +1133,7 @@ void
virTypedParamsClear(virTypedParameterPtr params,
int nparams)
{
int i;
size_t i;
if (!params)
return;
......
......@@ -274,7 +274,7 @@ cleanup:
char *virURIFormatParams(virURIPtr uri)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
int i;
size_t i;
bool amp = false;
for (i = 0; i < uri->paramsCount; ++i) {
......
......@@ -432,7 +432,7 @@ static void
virUSBDeviceListDispose(void *obj)
{
virUSBDeviceListPtr list = obj;
int i;
size_t i;
for (i = 0; i < list->count; i++)
virUSBDeviceFree(list->devs[i]);
......@@ -481,7 +481,7 @@ virUSBDeviceListSteal(virUSBDeviceListPtr list,
virUSBDevicePtr dev)
{
virUSBDevicePtr ret = NULL;
int i;
size_t i;
for (i = 0; i < list->count; i++) {
if (list->devs[i]->bus != dev->bus ||
......@@ -516,7 +516,7 @@ virUSBDevicePtr
virUSBDeviceListFind(virUSBDeviceListPtr list,
virUSBDevicePtr dev)
{
int i;
size_t i;
for (i = 0; i < list->count; i++) {
if (list->devs[i]->bus == dev->bus &&
......
......@@ -135,7 +135,7 @@ virPipeReadUntilEOF(int outfd, int errfd,
char **outbuf, char **errbuf) {
struct pollfd fds[2];
int i;
size_t i;
bool finished[2];
fds[0].fd = outfd;
......@@ -380,7 +380,7 @@ int virEnumFromString(const char *const*types,
unsigned int ntypes,
const char *type)
{
unsigned int i;
size_t i;
if (!type)
return -1;
......@@ -503,7 +503,7 @@ int virDiskNameToIndex(const char *name) {
const char *ptr = NULL;
int idx = 0;
static char const* const drive_prefix[] = {"fd", "hd", "vd", "sd", "xvd", "ubd"};
unsigned int i;
size_t i;
for (i = 0; i < ARRAY_CARDINALITY(drive_prefix); i++) {
if (STRPREFIX(name, drive_prefix[i])) {
......@@ -535,7 +535,9 @@ int virDiskNameToIndex(const char *name) {
char *virIndexToDiskName(int idx, const char *prefix)
{
char *name = NULL;
int i, k, offset;
size_t i;
int ctr;
int offset;
if (idx < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
......@@ -543,7 +545,7 @@ char *virIndexToDiskName(int idx, const char *prefix)
return NULL;
}
for (i = 0, k = idx; k >= 0; ++i, k = k / 26 - 1) { }
for (i = 0, ctr = idx; ctr >= 0; ++i, ctr = ctr / 26 - 1) { }
offset = strlen(prefix);
......@@ -553,8 +555,8 @@ char *virIndexToDiskName(int idx, const char *prefix)
strcpy(name, prefix);
name[offset + i] = '\0';
for (i = i - 1, k = idx; k >= 0; --i, k = k / 26 - 1) {
name[offset + i] = 'a' + (k % 26);
for (i = i - 1, ctr = idx; ctr >= 0; --i, ctr = ctr / 26 - 1) {
name[offset + i] = 'a' + (ctr % 26);
}
return name;
......@@ -1261,7 +1263,8 @@ int
virSetUIDGIDWithCaps(uid_t uid, gid_t gid, unsigned long long capBits,
bool clearExistingCaps)
{
int ii, capng_ret, ret = -1;
size_t i;
int capng_ret, ret = -1;
bool need_setgid = false, need_setuid = false;
bool need_setpcap = false;
......@@ -1274,12 +1277,12 @@ virSetUIDGIDWithCaps(uid_t uid, gid_t gid, unsigned long long capBits,
if (clearExistingCaps || (uid != (uid_t)-1 && uid != 0))
capng_clear(CAPNG_SELECT_BOTH);
for (ii = 0; ii <= CAP_LAST_CAP; ii++) {
if (capBits & (1ULL << ii)) {
for (i = 0; i <= CAP_LAST_CAP; i++) {
if (capBits & (1ULL << i)) {
capng_update(CAPNG_ADD,
CAPNG_EFFECTIVE|CAPNG_INHERITABLE|
CAPNG_PERMITTED|CAPNG_BOUNDING_SET,
ii);
i);
}
}
......@@ -1430,7 +1433,7 @@ bool virIsDevMapperDevice(const char *dev_name ATTRIBUTE_UNUSED)
bool
virValidateWWN(const char *wwn) {
int i;
size_t i;
const char *p = wwn;
if (STRPREFIX(wwn, "0x")) {
......@@ -1454,7 +1457,7 @@ virValidateWWN(const char *wwn) {
bool
virStrIsPrint(const char *str)
{
int i;
size_t i;
for (i = 0; str[i]; i++)
if (!c_isprint(str[i]))
......
......@@ -149,7 +149,7 @@ virUUIDGenerate(unsigned char *uuid)
int
virUUIDParse(const char *uuidstr, unsigned char *uuid) {
const char *cur;
int i;
size_t i;
/*
* do a liberal scan allowing '-' and ' ' anywhere between character
......@@ -233,7 +233,8 @@ virUUIDFormat(const unsigned char *uuid, char *uuidstr)
int
virUUIDIsValid(unsigned char *uuid)
{
unsigned int i, ctr = 1;
size_t i;
unsigned int ctr = 1;
unsigned char c;
if (!uuid)
......@@ -251,7 +252,7 @@ virUUIDIsValid(unsigned char *uuid)
static int
getDMISystemUUID(char *uuid, int len)
{
unsigned int i = 0;
size_t i = 0;
const char *paths[] = {
"/sys/devices/virtual/dmi/id/product_uuid",
"/sys/class/dmi/id/product_uuid",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册