]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: forbid 'int foo = true'
authorEric Blake <eblake@redhat.com>
Mon, 17 Nov 2014 23:39:48 +0000 (16:39 -0700)
committerEric Blake <eblake@redhat.com>
Wed, 19 Nov 2014 15:20:39 +0000 (08:20 -0700)
I noticed this while working on qemuDomainGetBlockInfo.  Assigning
a bool value to an int variable compiles fine, but raises red flags
on the maintenance front as it becomes too easy to assign -1 or 2
or any other non-bool value to the same variable.

* cfg.mk (sc_prohibit_int_assign_bool): New rule.
* src/conf/snapshot_conf.c (virDomainSnapshotRedefinePrep): Fix
offenders.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotCreateXML): Likewise.
* src/test/test_driver.c (testDomainSnapshotAlignDisks):
Likewise.
* src/util/vircgroup.c (virCgroupSupportsCpuBW): Likewise.
* src/util/virpci.c (virPCIDeviceBindToStub): Likewise.
* src/util/virutil.c (virIsCapableVport): Likewise.
* tools/virsh-domain-monitor.c (cmdDomMemStat): Likewise.
* tools/virsh-domain.c (cmdBlockResize, cmdScreenshot)
(cmdInjectNMI, cmdSendKey, cmdSendProcessSignal)
(cmdDetachInterface): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
cfg.mk
src/conf/snapshot_conf.c
src/qemu/qemu_driver.c
src/test/test_driver.c
src/util/vircgroup.c
src/util/virpci.c
src/util/virutil.c
tools/virsh-domain-monitor.c
tools/virsh-domain.c

diff --git a/cfg.mk b/cfg.mk
index f188645e20f65715138ec1980cf4484864e72d2d..c49f4f3a02ca4146c02c9cc3343e878fa1756fe2 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -584,6 +584,12 @@ sc_prohibit_loop_var_decl:
        halt='declare loop iterators outside the for statement'         \
          $(_sc_search_regexp)
 
+# Use 'bool', not 'int', when assigning true or false
+sc_prohibit_int_assign_bool:
+       @prohibit='\<int\>.*= *(true|false)'                            \
+       halt='use bool type for boolean values'                         \
+         $(_sc_search_regexp)
+
 # Many of the function names below came from this filter:
 # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \
 # |sed 's/.*\.c-  *//'|perl -pe 's/ ?\(.*//'|sort -u \
index 1f83b2c2a6aa590b5e60d0116f6f50081da6d388..c2caf3311c0ac04e887fa7bd64aef52ab1c47cc4 100644 (file)
@@ -1182,7 +1182,7 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
     virDomainSnapshotDefPtr def = *defptr;
     int ret = -1;
     int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
-    int align_match = true;
+    bool align_match = true;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     virDomainSnapshotObjPtr other;
 
index a84fd479e7e0e6e62681e81856d5e73c31674c9f..74d1bdc639fc60972c8a6898b0e6c5c910211f55 100644 (file)
@@ -10933,7 +10933,7 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
     struct stat sb;
     int idx;
     int format;
-    int activeFail = false;
+    bool activeFail = false;
     virQEMUDriverConfigPtr cfg = NULL;
     char *alias = NULL;
     char *buf = NULL;
@@ -13809,7 +13809,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
     unsigned int parse_flags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
     virDomainSnapshotObjPtr other = NULL;
     int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
-    int align_match = true;
+    bool align_match = true;
     virQEMUDriverConfigPtr cfg = NULL;
     virCapsPtr caps = NULL;
 
index d7844bdeae3e5f61a8174493c6805ed4648e823b..4b7fea1639eebafc2e9fe57e463671e0a14e5872 100644 (file)
@@ -6835,7 +6835,7 @@ testDomainSnapshotAlignDisks(virDomainObjPtr vm,
                              unsigned int flags)
 {
     int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
-    int align_match = true;
+    bool align_match = true;
 
     if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
         align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
index 9bbe694a9827fd8a9b84f0b8450b9c923c9f98dd..166f4dc7274b3c556d17d0c75bb0aff48f2d2689 100644 (file)
@@ -3908,7 +3908,7 @@ bool
 virCgroupSupportsCpuBW(virCgroupPtr cgroup)
 {
     char *path = NULL;
-    int ret = false;
+    bool ret = false;
 
     if (!cgroup)
         return false;
index f60d0fa6402c9a09c23912a661da247f38158c87..cd78212a00218e3eb2810003d26e9df80d949016 100644 (file)
@@ -1182,7 +1182,7 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev,
                        const char *stubDriverName)
 {
     int result = -1;
-    int reprobe = false;
+    bool reprobe = false;
     char *stubDriverPath = NULL;
     char *driverLink = NULL;
     char *path = NULL; /* reused for different purposes */
index 88c8baf46d53ea1972e8fbf1ac99de4ab2cbc68d..9c40317d09e0690ad4b7a056eae02c8301807337 100644 (file)
@@ -1995,7 +1995,7 @@ virIsCapableVport(const char *sysfs_prefix,
 {
     char *scsi_host_path = NULL;
     char *fc_host_path = NULL;
-    int ret = false;
+    bool ret = false;
 
     if (virAsprintf(&fc_host_path,
                     "%s/host%d/%s",
index 4e434f89d06bb4d93324bd638eca89874989fb8f..259400ffa843e5c43faa6f70514732ca6765483b 100644 (file)
@@ -298,7 +298,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
     virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
     unsigned int nr_stats;
     size_t i;
-    int ret = false;
+    bool ret = false;
     int rv = 0;
     int period = -1;
     bool config = vshCommandOptBool(cmd, "config");
index a7e91511e96c7b565a8a72ce5bd2c45c77685c84..d48765aeb2dd869fcab92504afe487a175cfcb22 100644 (file)
@@ -2640,7 +2640,7 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd)
     const char *path = NULL;
     unsigned long long size = 0;
     unsigned int flags = 0;
-    int ret = false;
+    bool ret = false;
 
     if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0)
         return false;
@@ -5163,7 +5163,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
     virStreamPtr st = NULL;
     unsigned int screen = 0;
     unsigned int flags = 0; /* currently unused */
-    int ret = false;
+    bool ret = false;
     bool created = false;
     bool generated = false;
     char *mime = NULL;
@@ -7615,7 +7615,7 @@ static bool
 cmdInjectNMI(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
-    int ret = true;
+    bool ret = true;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -7678,7 +7678,7 @@ static bool
 cmdSendKey(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
-    int ret = false;
+    bool ret = false;
     const char *codeset_option;
     int codeset;
     unsigned int holdtime = 0;
@@ -7809,7 +7809,7 @@ static bool
 cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
-    int ret = false;
+    bool ret = false;
     const char *pidstr;
     const char *signame;
     long long pid_value;
@@ -10592,7 +10592,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
     int diff_mac;
     size_t i;
     int ret;
-    int functionReturn = false;
+    bool functionReturn = false;
     unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
     bool current = vshCommandOptBool(cmd, "current");
     bool config = vshCommandOptBool(cmd, "config");