[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [ocaml PATCH] Cast virError* enums to int for comparisons with 0



The actual type of an enum in C is implementation defined when there are
no negative values, and thus it can be int, or uint.  This is the case
of the virError* enums in libvirt, as they do not have negative values.

Hence, to avoid hitting tautological comparison errors when checking
their rage, temporarly cast the enum values to int when checking they
are not negative.  The check is there to ensure the value is within the
range of the OCaml type used to represent it.

Signed-off-by: Pino Toscano <ptoscano redhat com>
---
 libvirt/libvirt_c_epilogue.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_epilogue.c
index 29656a4..4e75d2f 100644
--- a/libvirt/libvirt_c_epilogue.c
+++ b/libvirt/libvirt_c_epilogue.c
@@ -153,7 +153,7 @@ Val_err_number (virErrorNumber code)
   CAMLparam0 ();
   CAMLlocal1 (rv);
 
-  if (0 <= code && code <= MAX_VIR_CODE)
+  if (0 <= (int) code && code <= MAX_VIR_CODE)
     rv = Val_int (code);
   else {
     rv = caml_alloc (1, 0);	/* VIR_ERR_UNKNOWN (code) */
@@ -169,7 +169,7 @@ Val_err_domain (virErrorDomain code)
   CAMLparam0 ();
   CAMLlocal1 (rv);
 
-  if (0 <= code && code <= MAX_VIR_DOMAIN)
+  if (0 <= (int) code && code <= MAX_VIR_DOMAIN)
     rv = Val_int (code);
   else {
     rv = caml_alloc (1, 0);	/* VIR_FROM_UNKNOWN (code) */
@@ -185,7 +185,7 @@ Val_err_level (virErrorLevel code)
   CAMLparam0 ();
   CAMLlocal1 (rv);
 
-  if (0 <= code && code <= MAX_VIR_LEVEL)
+  if (0 <= (int) code && code <= MAX_VIR_LEVEL)
     rv = Val_int (code);
   else {
     rv = caml_alloc (1, 0);	/* VIR_ERR_UNKNOWN_LEVEL (code) */
-- 
2.17.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]