diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-12 07:58:18 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-02-04 14:03:13 +0100 |
commit | 9854463f16a3b98c55494e40f909d3b1f5f39192 (patch) | |
tree | 127f2b0ba740413a43e97987c4374cab75f953ab | |
parent | 192a7bec9660663733bf9fcb9038b385fb1187df (diff) | |
download | tigervnc-9854463f16a3b98c55494e40f909d3b1f5f39192.tar.gz tigervnc-9854463f16a3b98c55494e40f909d3b1f5f39192.zip |
Warn if Point/Rect/Region methods are used wrong
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.
-rw-r--r-- | common/rfb/Rect.h | 24 | ||||
-rw-r--r-- | common/rfb/Region.h | 9 |
2 files changed, 24 insertions, 9 deletions
diff --git a/common/rfb/Rect.h b/common/rfb/Rect.h index b5ae2548..bd9b160a 100644 --- a/common/rfb/Rect.h +++ b/common/rfb/Rect.h @@ -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);} diff --git a/common/rfb/Region.h b/common/rfb/Region.h index 6ac3a75b..eb16861e 100644 --- a/common/rfb/Region.h +++ b/common/rfb/Region.h @@ -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; |