mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
maint: forbid 'int foo = true'
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>
This commit is contained in:
parent
2aa167cafd
commit
eb9093763f
6
cfg.mk
6
cfg.mk
@ -584,6 +584,12 @@ sc_prohibit_loop_var_decl:
|
|||||||
halt='declare loop iterators outside the for statement' \
|
halt='declare loop iterators outside the for statement' \
|
||||||
$(_sc_search_regexp)
|
$(_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:
|
# Many of the function names below came from this filter:
|
||||||
# git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \
|
# git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \
|
||||||
# |sed 's/.*\.c- *//'|perl -pe 's/ ?\(.*//'|sort -u \
|
# |sed 's/.*\.c- *//'|perl -pe 's/ ?\(.*//'|sort -u \
|
||||||
|
@ -1182,7 +1182,7 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
|
|||||||
virDomainSnapshotDefPtr def = *defptr;
|
virDomainSnapshotDefPtr def = *defptr;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
||||||
int align_match = true;
|
bool align_match = true;
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
virDomainSnapshotObjPtr other;
|
virDomainSnapshotObjPtr other;
|
||||||
|
|
||||||
|
@ -10933,7 +10933,7 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
|
|||||||
struct stat sb;
|
struct stat sb;
|
||||||
int idx;
|
int idx;
|
||||||
int format;
|
int format;
|
||||||
int activeFail = false;
|
bool activeFail = false;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
virQEMUDriverConfigPtr cfg = NULL;
|
||||||
char *alias = NULL;
|
char *alias = NULL;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
@ -13809,7 +13809,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
|
|||||||
unsigned int parse_flags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
|
unsigned int parse_flags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
|
||||||
virDomainSnapshotObjPtr other = NULL;
|
virDomainSnapshotObjPtr other = NULL;
|
||||||
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
||||||
int align_match = true;
|
bool align_match = true;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
virQEMUDriverConfigPtr cfg = NULL;
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
|
|
||||||
|
@ -6835,7 +6835,7 @@ testDomainSnapshotAlignDisks(virDomainObjPtr vm,
|
|||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
int align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
||||||
int align_match = true;
|
bool align_match = true;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
|
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
|
||||||
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
||||||
|
@ -3908,7 +3908,7 @@ bool
|
|||||||
virCgroupSupportsCpuBW(virCgroupPtr cgroup)
|
virCgroupSupportsCpuBW(virCgroupPtr cgroup)
|
||||||
{
|
{
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
int ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (!cgroup)
|
if (!cgroup)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1182,7 +1182,7 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev,
|
|||||||
const char *stubDriverName)
|
const char *stubDriverName)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
int reprobe = false;
|
bool reprobe = false;
|
||||||
char *stubDriverPath = NULL;
|
char *stubDriverPath = NULL;
|
||||||
char *driverLink = NULL;
|
char *driverLink = NULL;
|
||||||
char *path = NULL; /* reused for different purposes */
|
char *path = NULL; /* reused for different purposes */
|
||||||
|
@ -1995,7 +1995,7 @@ virIsCapableVport(const char *sysfs_prefix,
|
|||||||
{
|
{
|
||||||
char *scsi_host_path = NULL;
|
char *scsi_host_path = NULL;
|
||||||
char *fc_host_path = NULL;
|
char *fc_host_path = NULL;
|
||||||
int ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (virAsprintf(&fc_host_path,
|
if (virAsprintf(&fc_host_path,
|
||||||
"%s/host%d/%s",
|
"%s/host%d/%s",
|
||||||
|
@ -298,7 +298,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
|
virDomainMemoryStatStruct stats[VIR_DOMAIN_MEMORY_STAT_NR];
|
||||||
unsigned int nr_stats;
|
unsigned int nr_stats;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = false;
|
bool ret = false;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
int period = -1;
|
int period = -1;
|
||||||
bool config = vshCommandOptBool(cmd, "config");
|
bool config = vshCommandOptBool(cmd, "config");
|
||||||
|
@ -2640,7 +2640,7 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *path = NULL;
|
const char *path = NULL;
|
||||||
unsigned long long size = 0;
|
unsigned long long size = 0;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
int ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -5163,7 +5163,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virStreamPtr st = NULL;
|
virStreamPtr st = NULL;
|
||||||
unsigned int screen = 0;
|
unsigned int screen = 0;
|
||||||
unsigned int flags = 0; /* currently unused */
|
unsigned int flags = 0; /* currently unused */
|
||||||
int ret = false;
|
bool ret = false;
|
||||||
bool created = false;
|
bool created = false;
|
||||||
bool generated = false;
|
bool generated = false;
|
||||||
char *mime = NULL;
|
char *mime = NULL;
|
||||||
@ -7615,7 +7615,7 @@ static bool
|
|||||||
cmdInjectNMI(vshControl *ctl, const vshCmd *cmd)
|
cmdInjectNMI(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
int ret = true;
|
bool ret = true;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
@ -7678,7 +7678,7 @@ static bool
|
|||||||
cmdSendKey(vshControl *ctl, const vshCmd *cmd)
|
cmdSendKey(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
int ret = false;
|
bool ret = false;
|
||||||
const char *codeset_option;
|
const char *codeset_option;
|
||||||
int codeset;
|
int codeset;
|
||||||
unsigned int holdtime = 0;
|
unsigned int holdtime = 0;
|
||||||
@ -7809,7 +7809,7 @@ static bool
|
|||||||
cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd)
|
cmdSendProcessSignal(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
int ret = false;
|
bool ret = false;
|
||||||
const char *pidstr;
|
const char *pidstr;
|
||||||
const char *signame;
|
const char *signame;
|
||||||
long long pid_value;
|
long long pid_value;
|
||||||
@ -10592,7 +10592,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int diff_mac;
|
int diff_mac;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
int functionReturn = false;
|
bool functionReturn = false;
|
||||||
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
||||||
bool current = vshCommandOptBool(cmd, "current");
|
bool current = vshCommandOptBool(cmd, "current");
|
||||||
bool config = vshCommandOptBool(cmd, "config");
|
bool config = vshCommandOptBool(cmd, "config");
|
||||||
|
Loading…
Reference in New Issue
Block a user