]> source.dussan.org Git - tigervnc.git/commitdiff
Warn if Point/Rect/Region methods are used wrong
authorPierre Ossman <ossman@cendio.se>
Thu, 12 Jan 2023 06:58:18 +0000 (07:58 +0100)
committerPierre Ossman <ossman@cendio.se>
Sat, 4 Feb 2023 13:03:13 +0000 (14:03 +0100)
It is easy to get confused if these methods modify the existing object,
or return a new one. So let's mark the return value as critical so the
compiler can help out if someone gets it wrong.

common/rfb/Rect.h
common/rfb/Region.h

index b5ae2548bfb8c79ae00fdbc37072a5b02b7324a7..bd9b160ad191c2faf4923f13e9e715b676094e73 100644 (file)
@@ -47,10 +47,16 @@ namespace rfb {
   struct Point {
     Point() : x(0), y(0) {}
     Point(int x_, int y_) : x(x_), y(y_) {}
-    inline Point negate() const {return Point(-x, -y);}
+    inline Point negate() const
+      __attribute__ ((warn_unused_result))
+      {return Point(-x, -y);}
     inline bool equals(const Point &p) const {return x==p.x && y==p.y;}
-    inline Point translate(const Point &p) const {return Point(x+p.x, y+p.y);}
-    inline Point subtract(const Point &p) const {return Point(x-p.x, y-p.y);}
+    inline Point translate(const Point &p) const
+      __attribute__ ((warn_unused_result))
+      {return Point(x+p.x, y+p.y);}
+    inline Point subtract(const Point &p) const
+      __attribute__ ((warn_unused_result))
+      {return Point(x-p.x, y-p.y);}
     int x, y;
   };
 
@@ -72,7 +78,9 @@ namespace rfb {
     inline void setXYWH(int x, int y, int w, int h) {
       tl.x = x; tl.y = y; br.x = x+w; br.y = y+h;
     }
-    inline Rect intersect(const Rect &r) const {
+    inline Rect intersect(const Rect &r) const
+      __attribute__ ((warn_unused_result))
+    {
       Rect result;
       result.tl.x = __rfbmax(tl.x, r.tl.x);
       result.tl.y = __rfbmax(tl.y, r.tl.y);
@@ -80,7 +88,9 @@ namespace rfb {
       result.br.y = __rfbmax(__rfbmin(br.y, r.br.y), result.tl.y);
       return result;
     }
-    inline Rect union_boundary(const Rect &r) const {
+    inline Rect union_boundary(const Rect &r) const
+      __attribute__ ((warn_unused_result))
+    {
       if (r.is_empty()) return *this;
       if (is_empty()) return r;
       Rect result;
@@ -90,7 +100,9 @@ namespace rfb {
       result.br.y = __rfbmax(br.y, r.br.y);
       return result;
     }
-    inline Rect translate(const Point &p) const {
+    inline Rect translate(const Point &p) const
+      __attribute__ ((warn_unused_result))
+    {
       return Rect(tl.translate(p), br.translate(p));
     }
     inline bool equals(const Rect &r) const {return r.tl.equals(tl) && r.br.equals(br);}
index 6ac3a75b555026ff950607fe0e588c2d953549f8..eb16861e9af576609ff61ef0d05f84e5245dffec 100644 (file)
@@ -53,9 +53,12 @@ namespace rfb {
 
     // the following three operations return a new region:
 
-    Region intersect(const Region& r) const;
-    Region union_(const Region& r) const;
-    Region subtract(const Region& r) const;
+    Region intersect(const Region& r) const
+      __attribute__ ((warn_unused_result));
+    Region union_(const Region& r) const
+      __attribute__ ((warn_unused_result));
+    Region subtract(const Region& r) const
+      __attribute__ ((warn_unused_result));
 
     bool equals(const Region& b) const;
     int numRects() const;