On 1/1/19 12:21 PM, Richard W.M. Jones wrote:
For mainly historical reasons we tended to use int to store boolean values. However using bool is probably safer in some corner cases (eg. ‘v == true’ can fail badly if v is an int, but works for bool).
The problems only occur when v is an int and set to something other than 0 or 1. But yes, in general using the bool type is worth doing.
bool was added in C99 so let's use it. --- server/internal.h | 16 +++++------ server/connections.c | 28 +++++++++--------- server/crypto.c | 4 +-- server/main.c | 67 ++++++++++++++++++++++---------------------- server/plugins.c | 2 +- 5 files changed, 59 insertions(+), 58 deletions(-)
+++ b/server/connections.c @@ -78,13 +78,13 @@ struct connection { uint32_t cflags; uint64_t exportsize; uint16_t eflags; - int readonly; - int can_flush; - int is_rotational; - int can_trim; - int can_zero; - int can_fua; - int using_tls; + bool readonly; + bool can_flush; + bool is_rotational; + bool can_trim; + bool can_zero; + bool can_fua; + bool using_tls;
Some of these were 'int' because they have tri-state returns from the client (-1 for error, or 0/1 for success). I suppose that making them bool means that you only store into it after checking for errors, but it does mean that we have to audit a bit more carefully that we aren't accidentally turning -1 into true. But I didn't spot any obvious problems, so I think the patch is good to go. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org