From: Peter Krempa Date: Thu, 5 Oct 2017 11:06:41 +0000 (+0200) Subject: util: Add functions to simplify bool->virTristate(Bool|Switch) assignment X-Git-Tag: CVE-2017-1000256~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d868366fe3eed36ab1c9280991b0789e5e857126;p=thirdparty%2Flibvirt.git util: Add functions to simplify bool->virTristate(Bool|Switch) assignment virTristateBoolFromBool and virTristateSwitchFromBool convert a boolean to the correct enum value. --- diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7a12d6a146..9243c55910 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2950,8 +2950,10 @@ virSetNonBlock; virSetSockReuseAddr; virSetUIDGID; virSetUIDGIDWithCaps; +virTristateBoolFromBool; virTristateBoolTypeFromString; virTristateBoolTypeToString; +virTristateSwitchFromBool; virTristateSwitchTypeFromString; virTristateSwitchTypeToString; virUpdateSelfLastChanged; diff --git a/src/util/virutil.c b/src/util/virutil.c index e08f9fa4ad..170e921920 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -100,6 +100,26 @@ VIR_ENUM_IMPL(virTristateSwitch, VIR_TRISTATE_SWITCH_LAST, "off") +virTristateBool +virTristateBoolFromBool(bool val) +{ + if (val) + return VIR_TRISTATE_BOOL_YES; + else + return VIR_TRISTATE_BOOL_NO; +} + + +virTristateSwitch +virTristateSwitchFromBool(bool val) +{ + if (val) + return VIR_TRISTATE_SWITCH_ON; + else + return VIR_TRISTATE_SWITCH_OFF; +} + + #ifndef WIN32 int virSetInherit(int fd, bool inherit) diff --git a/src/util/virutil.h b/src/util/virutil.h index 49382557f6..a862a8a637 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -193,6 +193,9 @@ typedef enum { VIR_ENUM_DECL(virTristateBool) VIR_ENUM_DECL(virTristateSwitch) +virTristateBool virTristateBoolFromBool(bool val); +virTristateSwitch virTristateSwitchFromBool(bool val); + /* the two enums must be in sync to be able to use helpers interchangeably in * some special cases */ verify((int)VIR_TRISTATE_BOOL_YES == (int)VIR_TRISTATE_SWITCH_ON);