From: "Daniel P. Berrange" <berrange(a)redhat.com>
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: Daniel P. Berrange <berrange(a)redhat.com>
---
tests/commandhelper.c | 4 ++--
tests/cputest.c | 6 +++---
tests/esxutilstest.c | 9 +++++----
tests/eventtest.c | 14 +++++++-------
tests/nodeinfotest.c | 2 +-
tests/openvzutilstest.c | 2 +-
tests/qemuhelptest.c | 6 +++---
tests/qemumonitorjsontest.c | 6 +++---
tests/qemumonitortest.c | 4 ++--
tests/ssh.c | 2 +-
tests/testutils.c | 13 +++++++------
tests/utiltest.c | 16 +++++++++-------
tests/viratomictest.c | 4 ++--
tests/virbitmaptest.c | 9 +++++----
tests/vircgrouptest.c | 2 +-
tests/virhashtest.c | 12 ++++++------
tests/virnetsockettest.c | 2 +-
tests/virstoragetest.c | 2 +-
18 files changed, 60 insertions(+), 55 deletions(-)
diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index e4cc5d2..ccddadf 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -56,7 +56,7 @@ static int envsort(const void *a, const void *b) {
}
int main(int argc, char **argv) {
- int i, n;
+ size_t i, n;
char **origenv;
char **newenv;
char *cwd;
@@ -103,7 +103,7 @@ int main(int argc, char **argv) {
closed = fcntl(i, F_GETFD, &f) == -1 &&
errno == EBADF;
if (!closed)
- fprintf(log, "FD:%d\n", i);
+ fprintf(log, "FD:%zu\n", i);
}
fprintf(log, "DAEMON:%s\n", getpgrp() == getsid(0) ? "yes" :
"no");
diff --git a/tests/cputest.c b/tests/cputest.c
index 0105440..d08550d 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -114,7 +114,7 @@ cpuTestLoadMultiXML(const char *arch,
xmlNodePtr *nodes = NULL;
virCPUDefPtr *cpus = NULL;
int n;
- int i;
+ size_t i;
if (virAsprintf(&xml, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch,
name) < 0)
goto cleanup;
@@ -326,7 +326,7 @@ cpuTestBaseline(const void *arg)
virCPUDefPtr baseline = NULL;
unsigned int ncpus = 0;
char *result = NULL;
- unsigned int i;
+ size_t i;
if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
goto cleanup;
@@ -359,7 +359,7 @@ cpuTestBaseline(const void *arg)
cmp != VIR_CPU_COMPARE_IDENTICAL) {
if (virTestGetVerbose()) {
fprintf(stderr,
- "\nbaseline CPU is incompatible with CPU %u\n", i);
+ "\nbaseline CPU is incompatible with CPU %zu\n", i);
fprintf(stderr, "%74s", "... ");
}
ret = -1;
diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index bb58a3a..221c46a 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -47,7 +47,8 @@ static struct testPath paths[] = {
static int
testParseDatastorePath(const void *data ATTRIBUTE_UNUSED)
{
- int i, result = 0;
+ int result = 0;
+ size_t i;
char *datastoreName = NULL;
char *directoryName = NULL;
char *directoryAndFileName = NULL;
@@ -135,7 +136,7 @@ static struct testDateTime times[] = {
static int
testConvertDateTimeToCalendarTime(const void *data ATTRIBUTE_UNUSED)
{
- int i;
+ size_t i;
esxVI_DateTime dateTime;
long long calendarTime;
@@ -187,7 +188,7 @@ static struct testDatastoreItem datastoreItems[] = {
static int
testEscapeDatastoreItem(const void *data ATTRIBUTE_UNUSED)
{
- int i;
+ size_t i;
char *escaped = NULL;
for (i = 0; i < ARRAY_CARDINALITY(datastoreItems); ++i) {
@@ -228,7 +229,7 @@ static struct testWindows1252ToUTF8 windows1252ToUTF8[] = {
static int
testConvertWindows1252ToUTF8(const void *data ATTRIBUTE_UNUSED)
{
- int i;
+ size_t i;
char *utf8 = NULL;
for (i = 0; i < ARRAY_CARDINALITY(windows1252ToUTF8); ++i) {
diff --git a/tests/eventtest.c b/tests/eventtest.c
index 97d805a..821745f 100644
--- a/tests/eventtest.c
+++ b/tests/eventtest.c
@@ -143,18 +143,18 @@ verifyFired(const char *name, int handle, int timer)
{
int handleFired = 0;
int timerFired = 0;
- int i;
+ size_t i;
for (i = 0; i < NUM_FDS; i++) {
if (handles[i].fired) {
if (i != handle) {
virtTestResult(name, 1,
- "Handle %d fired, but expected %d\n", i,
+ "Handle %zu fired, but expected %d\n", i,
handle);
return EXIT_FAILURE;
} else {
if (handles[i].error != EV_ERROR_NONE) {
virtTestResult(name, 1,
- "Handle %d fired, but had error %d\n", i,
+ "Handle %zu fired, but had error %d\n", i,
handles[i].error);
return EXIT_FAILURE;
}
@@ -181,12 +181,12 @@ verifyFired(const char *name, int handle, int timer)
if (timers[i].fired) {
if (i != timer) {
virtTestResult(name, 1,
- "Timer %d fired, but expected %d\n", i, timer);
+ "Timer %zu fired, but expected %d\n", i,
timer);
return EXIT_FAILURE;
} else {
if (timers[i].error != EV_ERROR_NONE) {
virtTestResult(name, 1,
- "Timer %d fired, but had error %d\n", i,
+ "Timer %zu fired, but had error %d\n", i,
timers[i].error);
return EXIT_FAILURE;
}
@@ -247,7 +247,7 @@ finishJob(const char *name, int handle, int timer)
static void
resetAll(void)
{
- int i;
+ size_t i;
for (i = 0; i < NUM_FDS; i++) {
handles[i].fired = 0;
handles[i].error = EV_ERROR_NONE;
@@ -261,7 +261,7 @@ resetAll(void)
static int
mymain(void)
{
- int i;
+ size_t i;
pthread_t eventThread;
char one = '1';
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index bce56f3..a4a5931 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -121,7 +121,7 @@ static int
mymain(void)
{
int ret = 0;
- int i;
+ size_t i;
const char *nodeData[] = {
"test1",
# if !(defined(__powerpc__) || \
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index 4850017..ee68c06 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -38,7 +38,7 @@ static int
testReadConfigParam(const void *data ATTRIBUTE_UNUSED)
{
int result = -1;
- int i;
+ size_t i;
char *conf = NULL;
char *value = NULL;
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index 2a3b019..72a1ad3 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -22,15 +22,15 @@ struct testInfo {
static void printMismatchedFlags(virQEMUCapsPtr got,
virQEMUCapsPtr expect)
{
- int i;
+ size_t i;
for (i = 0; i < QEMU_CAPS_LAST; i++) {
bool gotFlag = virQEMUCapsGet(got, i);
bool expectFlag = virQEMUCapsGet(expect, i);
if (gotFlag && !expectFlag)
- fprintf(stderr, "Extra flag %i\n", i);
+ fprintf(stderr, "Extra flag %zu\n", i);
if (!gotFlag && expectFlag)
- fprintf(stderr, "Missing flag %i\n", i);
+ fprintf(stderr, "Missing flag %zu\n", i);
}
}
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index acc94ca..14d3700 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -236,7 +236,7 @@ testQemuMonitorJSONGetMachines(const void *data)
qemuMonitorMachineInfoPtr *info;
int ninfo = 0;
const char *null = NULL;
- int i;
+ size_t i;
if (!test)
return -1;
@@ -317,7 +317,7 @@ testQemuMonitorJSONGetCPUDefinitions(const void *data)
int ret = -1;
char **cpus = NULL;
int ncpus = 0;
- int i;
+ size_t i;
if (!test)
return -1;
@@ -383,7 +383,7 @@ testQemuMonitorJSONGetCommands(const void *data)
int ret = -1;
char **commands = NULL;
int ncommands = 0;
- int i;
+ size_t i;
if (!test)
return -1;
diff --git a/tests/qemumonitortest.c b/tests/qemumonitortest.c
index 61ac2d6..3851251 100644
--- a/tests/qemumonitortest.c
+++ b/tests/qemumonitortest.c
@@ -34,7 +34,7 @@ static struct testEscapeString escapeStrings[] = {
static int testEscapeArg(const void *data ATTRIBUTE_UNUSED)
{
- int i;
+ size_t i;
char *escaped = NULL;
for (i = 0; i < ARRAY_CARDINALITY(escapeStrings); ++i) {
escaped = qemuMonitorEscapeArg(escapeStrings[i].unescaped);
@@ -61,7 +61,7 @@ static int testEscapeArg(const void *data ATTRIBUTE_UNUSED)
static int testUnescapeArg(const void *data ATTRIBUTE_UNUSED)
{
- int i;
+ size_t i;
char *unescaped = NULL;
for (i = 0; i < ARRAY_CARDINALITY(escapeStrings); ++i) {
unescaped = qemuMonitorUnescapeArg(escapeStrings[i].escaped);
diff --git a/tests/ssh.c b/tests/ssh.c
index 56b2e9b..76c60d3 100644
--- a/tests/ssh.c
+++ b/tests/ssh.c
@@ -28,7 +28,7 @@
int main(int argc, char **argv)
{
- int i;
+ size_t i;
bool failConnect = false; /* Exit -1, with no data on stdout, msg on stderr */
bool dieEarly = false; /* Exit -1, with partial data on stdout, msg on stderr */
diff --git a/tests/testutils.c b/tests/testutils.c
index 528e432..993c87f 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -77,7 +77,7 @@ double
virtTestCountAverage(double *items, int nitems)
{
long double sum = 0;
- int i;
+ size_t i;
for (i=1; i < nitems; i++)
sum += items[i];
@@ -132,7 +132,8 @@ void virtTestResult(const char *name, int ret, const char *msg, ...)
int
virtTestRun(const char *title, int nloops, int (*body)(const void *data), const void
*data)
{
- int i, ret = 0;
+ int ret = 0;
+ size_t i;
double *ts = NULL;
if (testCounter == 0 && !virTestGetVerbose())
@@ -265,7 +266,7 @@ virtTestLoadFile(const char *file, char **buf)
static
void virtTestCaptureProgramExecChild(const char *const argv[],
int pipefd) {
- int i;
+ size_t i;
int open_max;
int stdinfd = -1;
const char *const env[] = {
@@ -523,7 +524,7 @@ virtTestErrorHook(int n, void *data ATTRIBUTE_UNUSED)
{
void *trace[30];
int ntrace = ARRAY_CARDINALITY(trace);
- int i;
+ size_t i;
char **symbols = NULL;
ntrace = backtrace(trace, ntrace);
@@ -665,7 +666,7 @@ int virtTestMain(int argc,
fprintf(stderr, "%d) OOM of %d allocs ", testCounter,
approxAlloc);
if (mp) {
- int i;
+ size_t i;
for (i = 0; i < mp; i++) {
workers[i] = fork();
if (workers[i] == 0) {
@@ -700,7 +701,7 @@ int virtTestMain(int argc,
if (worker) {
_exit(ret);
} else {
- int i;
+ size_t i;
for (i = 0; i < mp; i++) {
if (virProcessWait(workers[i], NULL) < 0)
ret = EXIT_FAILURE;
diff --git a/tests/utiltest.c b/tests/utiltest.c
index 9d18652..0cbf3f3 100644
--- a/tests/utiltest.c
+++ b/tests/utiltest.c
@@ -36,7 +36,7 @@ static const char* diskNames[] = {
static int
testIndexToDiskName(const void *data ATTRIBUTE_UNUSED)
{
- int i;
+ size_t i;
char *diskName = NULL;
for (i = 0; i < ARRAY_CARDINALITY(diskNames); ++i) {
@@ -62,19 +62,20 @@ testIndexToDiskName(const void *data ATTRIBUTE_UNUSED)
static int
testDiskNameToIndex(const void *data ATTRIBUTE_UNUSED)
{
- int i, k;
+ size_t i;
+ int idx;
char *diskName = NULL;
for (i = 0; i < 100000; ++i) {
VIR_FREE(diskName);
diskName = virIndexToDiskName(i, "sd");
- k = virDiskNameToIndex(diskName);
+ idx = virDiskNameToIndex(diskName);
- if (k != i) {
+ if (idx < 0 || idx != i) {
if (virTestGetDebug() > 0) {
- fprintf(stderr, "\nExpect [%d]\n", i);
- fprintf(stderr, "Actual [%d]\n", k);
+ fprintf(stderr, "\nExpect [%zu]\n", i);
+ fprintf(stderr, "Actual [%d]\n", idx);
}
VIR_FREE(diskName);
@@ -115,7 +116,8 @@ static struct testVersionString versions[] = {
static int
testParseVersionString(const void *data ATTRIBUTE_UNUSED)
{
- int i, result;
+ int result;
+ size_t i;
unsigned long version;
for (i = 0; i < ARRAY_CARDINALITY(versions); ++i) {
diff --git a/tests/viratomictest.c b/tests/viratomictest.c
index 1ed1707..40a05b8 100644
--- a/tests/viratomictest.c
+++ b/tests/viratomictest.c
@@ -115,7 +115,7 @@ static void
thread_func(void *data)
{
int idx = (intptr_t)data;
- int i;
+ size_t i;
int d;
for (i = 0; i < ROUNDS; i++) {
@@ -134,7 +134,7 @@ static int
testThreads(const void *data ATTRIBUTE_UNUSED)
{
int sum;
- int i;
+ size_t i;
virThread threads[THREADS];
atomic = 0;
diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
index 2464c33..11047c6 100644
--- a/tests/virbitmaptest.c
+++ b/tests/virbitmaptest.c
@@ -65,7 +65,7 @@ testBit(virBitmapPtr bitmap,
unsigned int end,
bool expected)
{
- int i;
+ size_t i;
bool result;
for (i = start; i <= end; i++) {
@@ -145,7 +145,7 @@ static int test3(const void *data ATTRIBUTE_UNUSED)
virBitmapPtr bitmap = NULL;
int ret = -1;
int size = 5;
- int i;
+ size_t i;
if ((bitmap = virBitmapNew(size)) == NULL)
goto error;
@@ -180,7 +180,7 @@ static int test4(const void *data ATTRIBUTE_UNUSED)
28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39
};
virBitmapPtr bitmap = NULL;
- int i, j;
+ size_t i, j;
if (ARRAY_CARDINALITY(bitsPos) + ARRAY_CARDINALITY(bitsPosInv) != size)
goto error;
@@ -268,7 +268,8 @@ static int test5(const void *v ATTRIBUTE_UNUSED)
int len2;
int bits[] = {0, 9, 34};
virBitmapPtr bitmap;
- int i, j;
+ size_t i;
+ ssize_t j;
int ret = -1;
bitmap = virBitmapNewData(data, sizeof(data));
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 262eb8b..22b40b4 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -41,7 +41,7 @@ static int validateCgroup(virCgroupPtr cgroup,
const char **expectLinkPoint,
const char **expectPlacement)
{
- int i;
+ size_t i;
if (STRNEQ(cgroup->path, expectPath)) {
fprintf(stderr, "Wrong path '%s', expected '%s'\n",
diff --git a/tests/virhashtest.c b/tests/virhashtest.c
index f36fc76..4cfd04e 100644
--- a/tests/virhashtest.c
+++ b/tests/virhashtest.c
@@ -128,7 +128,7 @@ testHashUpdate(const void *data ATTRIBUTE_UNUSED)
{
int count = ARRAY_CARDINALITY(uuids) + ARRAY_CARDINALITY(uuids_new);
virHashTablePtr hash;
- int i;
+ size_t i;
int ret = -1;
if (!(hash = testHashInit(0)))
@@ -170,7 +170,7 @@ testHashRemove(const void *data ATTRIBUTE_UNUSED)
{
int count = ARRAY_CARDINALITY(uuids) - ARRAY_CARDINALITY(uuids_subset);
virHashTablePtr hash;
- int i;
+ size_t i;
int ret = -1;
if (!(hash = testHashInit(0)))
@@ -206,7 +206,7 @@ testHashRemoveForEachSome(void *payload ATTRIBUTE_UNUSED,
void *data)
{
virHashTablePtr hash = data;
- int i;
+ size_t i;
for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) {
if (STREQ(uuids_subset[i], name)) {
@@ -241,7 +241,7 @@ testHashRemoveForEachForbidden(void *payload ATTRIBUTE_UNUSED,
void *data)
{
virHashTablePtr hash = data;
- int i;
+ size_t i;
for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) {
if (STREQ(uuids_subset[i], name)) {
@@ -297,7 +297,7 @@ testHashSteal(const void *data ATTRIBUTE_UNUSED)
{
int count = ARRAY_CARDINALITY(uuids) - ARRAY_CARDINALITY(uuids_subset);
virHashTablePtr hash;
- int i;
+ size_t i;
int ret = -1;
if (!(hash = testHashInit(0)))
@@ -402,7 +402,7 @@ testHashRemoveSetIter(const void *payload ATTRIBUTE_UNUSED,
{
int *count = (int *) data;
bool rem = false;
- int i;
+ size_t i;
for (i = 0; i < ARRAY_CARDINALITY(uuids_subset); i++) {
if (STREQ(uuids_subset[i], name)) {
diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c
index 4c5a0ea..5b434ba 100644
--- a/tests/virnetsockettest.c
+++ b/tests/virnetsockettest.c
@@ -52,7 +52,7 @@ checkProtocols(bool *hasIPv4, bool *hasIPv6,
struct sockaddr_in in4;
struct sockaddr_in6 in6;
int s4 = -1, s6 = -1;
- int i;
+ size_t i;
int ret = -1;
memset(&hints, 0, sizeof(hints));
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index fef4b37..d87080e 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -220,7 +220,7 @@ testStorageChain(const void *args)
int ret = -1;
virStorageFileMetadataPtr meta;
virStorageFileMetadataPtr elt;
- int i = 0;
+ size_t i = 0;
meta = virStorageFileGetMetadata(data->start, data->format, -1, -1,
(data->flags & ALLOW_PROBE) != 0);
--
1.8.1.4