Skip to content

Commit

Permalink
Disable automatic conversions from void * to bool.
Browse files Browse the repository at this point in the history
It leads to various bugs, e.g., when "struct * _zend_string" is passed
where zval was in php < 8.0.
  • Loading branch information
ebikt committed Apr 16, 2024
1 parent cfc3460 commit 5890384
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class PHPCPP_EXPORT Class : private ClassBase
Class<T> &property(const char *name, const char *value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
Class<T> &property(const char *name, const std::string &value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
Class<T> &property(const char *name, bool value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }
Class<T> &property(const char *name, const void *value, int flags = Public) = delete;
Class<T> &property(const char *name, double value, int flags = Public) { ClassBase::property(name, value, flags); return *this; }

/**
Expand Down
1 change: 1 addition & 0 deletions include/classbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class PHPCPP_EXPORT ClassBase
void property(const char *name, int32_t value, int flags = Php::Public);
void property(const char *name, int64_t value, int flags = Php::Public);
void property(const char *name, bool value, int flags = Php::Public);
void property(const char *name, const void *value, int flags = Php::Public) = delete;
void property(const char *name, char value, int flags = Php::Public);
void property(const char *name, const std::string &value, int flags = Php::Public);
void property(const char *name, const char *value, int flags = Php::Public);
Expand Down
1 change: 1 addition & 0 deletions include/constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PHPCPP_EXPORT Constant
* @param value Constant's value
*/
Constant(const char *name, bool value);
Constant(const char *name, const void *value) = delete;

/**
* Constructor to create a constant for a 32-bit integer
Expand Down
10 changes: 10 additions & 0 deletions include/hashmember.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
HashMember &operator+=(int32_t value) { return operator=(this->value() + value); }
HashMember &operator+=(int64_t value) { return operator=(this->value() + value); }
HashMember &operator+=(bool value) { return operator=(this->value() + value); }
HashMember &operator+=(const void *value) = delete;
HashMember &operator+=(char value) { return operator=(this->value() + value); }
HashMember &operator+=(const std::string &value) { return operator=(this->value() + value); }
HashMember &operator+=(const char *value) { return operator=(this->value() + value); }
Expand All @@ -206,6 +207,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
HashMember &operator-=(int32_t value) { return operator=(this->value() - value); }
HashMember &operator-=(int64_t value) { return operator=(this->value() - value); }
HashMember &operator-=(bool value) { return operator=(this->value() - value); }
HashMember &operator-=(const void *value) = delete;
HashMember &operator-=(char value) { return operator=(this->value() - value); }
HashMember &operator-=(const std::string &value) { return operator=(this->value() - value); }
HashMember &operator-=(const char *value) { return operator=(this->value() - value); }
Expand All @@ -221,6 +223,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
HashMember &operator*=(int32_t value) { return operator=(this->value() * value); }
HashMember &operator*=(int64_t value) { return operator=(this->value() * value); }
HashMember &operator*=(bool value) { return operator=(this->value() * value); }
HashMember &operator*=(const void *value) = delete;
HashMember &operator*=(char value) { return operator=(this->value() * value); }
HashMember &operator*=(const std::string &value) { return operator=(this->value() * value); }
HashMember &operator*=(const char *value) { return operator=(this->value() * value); }
Expand All @@ -236,6 +239,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
HashMember &operator/=(int32_t value) { return operator=(this->value() / value); }
HashMember &operator/=(int64_t value) { return operator=(this->value() / value); }
HashMember &operator/=(bool value) { return operator=(this->value() / value); }
HashMember &operator/=(const void *value) = delete;
HashMember &operator/=(char value) { return operator=(this->value() / value); }
HashMember &operator/=(const std::string &value) { return operator=(this->value() / value); }
HashMember &operator/=(const char *value) { return operator=(this->value() / value); }
Expand All @@ -251,6 +255,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
HashMember &operator%=(int32_t value) { return operator=(this->value() % value); }
HashMember &operator%=(int64_t value) { return operator=(this->value() % value); }
HashMember &operator%=(bool value) { return operator=(this->value() % value); }
HashMember &operator%=(const void *value) = delete;
HashMember &operator%=(char value) { return operator=(this->value() % value); }
HashMember &operator%=(const std::string &value) { return operator=(this->value() % value); }
HashMember &operator%=(const char *value) { return operator=(this->value() % value); }
Expand All @@ -266,6 +271,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
Value operator+(int32_t value) { return this->value() + value; }
Value operator+(int64_t value) { return this->value() + value; }
Value operator+(bool value) { return this->value() + value; }
Value operator+(const void *value) = delete;
Value operator+(char value) { return this->value() + value; }
Value operator+(const std::string &value) { return this->value() + value; }
Value operator+(const char *value) { return this->value() + value; }
Expand All @@ -281,6 +287,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
Value operator-(int32_t value) { return this->value() - value; }
Value operator-(int64_t value) { return this->value() - value; }
Value operator-(bool value) { return this->value() - value; }
Value operator-(const void *value) = delete;
Value operator-(char value) { return this->value() - value; }
Value operator-(const std::string &value) { return this->value() - value; }
Value operator-(const char *value) { return this->value() - value; }
Expand All @@ -296,6 +303,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
Value operator*(int32_t value) { return this->value() * value; }
Value operator*(int64_t value) { return this->value() * value; }
Value operator*(bool value) { return this->value() * value; }
Value operator*(const void *value) = delete;
Value operator*(char value) { return this->value() * value; }
Value operator*(const std::string &value) { return this->value() * value; }
Value operator*(const char *value) { return this->value() * value; }
Expand All @@ -311,6 +319,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
Value operator/(int32_t value) { return this->value() / value; }
Value operator/(int64_t value) { return this->value() / value; }
Value operator/(bool value) { return this->value() / value; }
Value operator/(const void *value) = delete;
Value operator/(char value) { return this->value() / value; }
Value operator/(const std::string &value) { return this->value() / value; }
Value operator/(const char *value) { return this->value() / value; }
Expand All @@ -326,6 +335,7 @@ class PHPCPP_EXPORT HashMember : private HashParent
Value operator%(int32_t value) { return this->value() % value; }
Value operator%(int64_t value) { return this->value() % value; }
Value operator%(bool value) { return this->value() % value; }
Value operator%(const void *value) = delete;
Value operator%(char value) { return this->value() % value; }
Value operator%(const std::string &value) { return this->value() % value; }
Value operator%(const char *value) { return this->value() % value; }
Expand Down
1 change: 1 addition & 0 deletions include/ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PHPCPP_EXPORT Ini
*/
Ini(const char *name, bool value, const Place place = Place::All) :
_name(name), _value(bool2str(value)), _place(place) {}
Ini(const char *name, const void *value, const Place place = Place::All) = delete;

/**
* Constructors for integer values
Expand Down
16 changes: 16 additions & 0 deletions include/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value(int32_t value);
Value(int64_t value);
Value(bool value);
Value(const void *value) = delete;
Value(char value);
Value(const std::string &value);
Value(const char *value, int size = -1);
Expand Down Expand Up @@ -174,6 +175,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value &operator=(int32_t value);
Value &operator=(int64_t value);
Value &operator=(bool value);
Value &operator=(const void *value) = delete;
Value &operator=(char value);
Value &operator=(const std::string &value);
Value &operator=(const char *value);
Expand All @@ -191,6 +193,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value &operator+=(int32_t value);
Value &operator+=(int64_t value);
Value &operator+=(bool value);
Value &operator+=(const void *value) = delete;
Value &operator+=(char value);
Value &operator+=(const std::string &value);
Value &operator+=(const char *value);
Expand All @@ -206,6 +209,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value &operator-=(int32_t value);
Value &operator-=(int64_t value);
Value &operator-=(bool value);
Value &operator-=(const void *value) = delete;
Value &operator-=(char value);
Value &operator-=(const std::string &value);
Value &operator-=(const char *value);
Expand All @@ -221,6 +225,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value &operator*=(int32_t value);
Value &operator*=(int64_t value);
Value &operator*=(bool value);
Value &operator*=(const void *value) = delete;
Value &operator*=(char value);
Value &operator*=(const std::string &value);
Value &operator*=(const char *value);
Expand All @@ -236,6 +241,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value &operator/=(int32_t value);
Value &operator/=(int64_t value);
Value &operator/=(bool value);
Value &operator/=(const void *value) = delete;
Value &operator/=(char value);
Value &operator/=(const std::string &value);
Value &operator/=(const char *value);
Expand All @@ -251,6 +257,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value &operator%=(int32_t value);
Value &operator%=(int64_t value);
Value &operator%=(bool value);
Value &operator%=(const void *value) = delete;
Value &operator%=(char value);
Value &operator%=(const std::string &value);
Value &operator%=(const char *value);
Expand All @@ -266,6 +273,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value operator+(int32_t value);
Value operator+(int64_t value);
Value operator+(bool value);
Value operator+(const void *value) = delete;
Value operator+(char value);
Value operator+(const std::string &value);
Value operator+(const char *value);
Expand All @@ -281,6 +289,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value operator-(int32_t value);
Value operator-(int64_t value);
Value operator-(bool value);
Value operator-(const void *value) = delete;
Value operator-(char value);
Value operator-(const std::string &value);
Value operator-(const char *value);
Expand All @@ -296,6 +305,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value operator*(int32_t value);
Value operator*(int64_t value);
Value operator*(bool value);
Value operator*(const void *value) = delete;
Value operator*(char value);
Value operator*(const std::string &value);
Value operator*(const char *value);
Expand All @@ -311,6 +321,7 @@ class PHPCPP_EXPORT Value : private HashParent
Value operator/(int32_t value);
Value operator/(int64_t value);
Value operator/(bool value);
Value operator/(const void *value) = delete;
Value operator/(char value);
Value operator/(const std::string &value);
Value operator/(const char *value);
Expand All @@ -326,13 +337,18 @@ class PHPCPP_EXPORT Value : private HashParent
Value operator%(int32_t value);
Value operator%(int64_t value);
Value operator%(bool value);
Value operator%(const void *value) = delete;
Value operator%(char value);
Value operator%(const std::string &value);
Value operator%(const char *value);
Value operator%(double value);

/**
* Comparison operators for hardcoded strings
*
* Note that this works only for string values,
* other values segfaults!
*
* @param value
*/
bool operator==(const char *value) const { return ::strcmp(rawValue(), value) == 0; }
Expand Down

0 comments on commit 5890384

Please sign in to comment.