[glibmm] Glib::ustring: Don't allow comparison to 0



commit 38fd0d5f90683075955a36ce7df7a77d689a34e1
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Fri Dec 11 18:16:26 2015 +0100

    Glib::ustring: Don't allow comparison to 0
    
    * glib/glibmm/ustring.h: Don't allow comparison of a ustring to an integer.
    Bug #572978.

 glib/glibmm/ustring.h |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/glib/glibmm/ustring.h b/glib/glibmm/ustring.h
index 94d6c35..a4e2fa8 100644
--- a/glib/glibmm/ustring.h
+++ b/glib/glibmm/ustring.h
@@ -1591,6 +1591,24 @@ inline bool operator>=(const ustring& lhs, const char* rhs)
 inline bool operator>=(const char* lhs, const ustring& rhs)
   { return (rhs.compare(lhs) <= 0); }
 
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+// Don't allow implicit conversion of integer 0 to nullptr in the relational operators.
+// If the int versions of the relational operators are not deleted, attempts to
+// compare with other integer values than 0 can result in really unexpected behaviour.
+// See https://bugzilla.gnome.org/show_bug.cgi?id=572978#c10
+bool operator==(const ustring& lhs, int rhs) = delete;
+bool operator==(int lhs, const ustring& rhs) = delete;
+bool operator!=(const ustring& lhs, int rhs) = delete;
+bool operator!=(int lhs, const ustring& rhs) = delete;
+bool operator<(const ustring& lhs, int rhs) = delete;
+bool operator<(int lhs, const ustring& rhs) = delete;
+bool operator>(const ustring& lhs, int rhs) = delete;
+bool operator>(int lhs, const ustring& rhs) = delete;
+bool operator<=(const ustring& lhs, int rhs) = delete;
+bool operator<=(int lhs, const ustring& rhs) = delete;
+bool operator>=(const ustring& lhs, int rhs) = delete;
+bool operator>=(int lhs, const ustring& rhs) = delete;
+#endif // DOXYGEN_SHOULD_SKIP_THIS
 
 /**** Glib::ustring -- concatenation operators *****************************/
 


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