mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Make nearly all bool operators explicit.
These are a bit dangerous because the casting can happen in quite unexpected circumstances and lead to undesirable comparison results.
This commit is contained in:
parent
5ed5587b5c
commit
41285abea5
7 changed files with 7 additions and 7 deletions
|
@ -102,7 +102,7 @@ public:
|
||||||
|
|
||||||
EventHandler* Ptr() { return handler; }
|
EventHandler* Ptr() { return handler; }
|
||||||
|
|
||||||
operator bool() const { return handler && *handler; }
|
explicit operator bool() const { return handler && *handler; }
|
||||||
EventHandler* operator->() { return handler; }
|
EventHandler* operator->() { return handler; }
|
||||||
const EventHandler* operator->() const { return handler; }
|
const EventHandler* operator->() const { return handler; }
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
* and not yet initialized w/ Set().
|
* and not yet initialized w/ Set().
|
||||||
* TODO: this would be better as an "explicit" conversion operator (C++11)
|
* TODO: this would be better as an "explicit" conversion operator (C++11)
|
||||||
*/
|
*/
|
||||||
operator bool() const
|
explicit operator bool() const
|
||||||
{ return initialized; }
|
{ return initialized; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
* "safe bool" idiom (not necessary if "explicit" is available),
|
* "safe bool" idiom (not necessary if "explicit" is available),
|
||||||
* otherwise this may allow nonsense/undesired comparison operations.
|
* otherwise this may allow nonsense/undesired comparison operations.
|
||||||
*/
|
*/
|
||||||
operator bool() const { return *this != Tag(); }
|
explicit operator bool() const { return *this != Tag(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assignment operator.
|
* Assignment operator.
|
||||||
|
|
|
@ -8,7 +8,7 @@ refine flow SIP_Flow += {
|
||||||
|
|
||||||
%init{
|
%init{
|
||||||
content_length = 0;
|
content_length = 0;
|
||||||
build_headers = (sip_all_headers != 0);
|
build_headers = bool(sip_all_headers);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
function get_content_length(): int
|
function get_content_length(): int
|
||||||
|
|
|
@ -448,7 +448,7 @@ bool Manager::IsDisabled(analyzer::Tag tag)
|
||||||
if ( ! disabled )
|
if ( ! disabled )
|
||||||
disabled = internal_const_val("Files::disable")->AsTableVal();
|
disabled = internal_const_val("Files::disable")->AsTableVal();
|
||||||
|
|
||||||
Val* index = new Val(tag, TYPE_COUNT);
|
Val* index = new Val(bool(tag), TYPE_COUNT);
|
||||||
Val* yield = disabled->Lookup(index);
|
Val* yield = disabled->Lookup(index);
|
||||||
Unref(index);
|
Unref(index);
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
* otherwise this may allow nonsense/undesired comparison operations.
|
* otherwise this may allow nonsense/undesired comparison operations.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
operator bool() const { return *this != Tag(); }
|
explicit operator bool() const { return *this != Tag(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assignment operator.
|
* Assignment operator.
|
||||||
|
|
|
@ -78,7 +78,7 @@ struct VersionNumber {
|
||||||
/**
|
/**
|
||||||
* Returns true if the version is set to a non-negative value.
|
* Returns true if the version is set to a non-negative value.
|
||||||
*/
|
*/
|
||||||
operator bool() const { return major >= 0 && minor >= 0; }
|
explicit operator bool() const { return major >= 0 && minor >= 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue