mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 04:44:34 +03:00
Actually detect negative sizes by following ES.106 (#1586)
* Actually detect negative sizes by following ES.106 And don't use senseless one letter names * fix grammar Co-Authored-By: Johel Ernesto Guerrero Peña <johelegp@gmail.com> Co-authored-by: Johel Ernesto Guerrero Peña <johelegp@gmail.com>
This commit is contained in:
@@ -20320,20 +20320,20 @@ and errors (when we didn't deal correctly with semi-constructed objects consiste
|
|||||||
|
|
||||||
class Picture
|
class Picture
|
||||||
{
|
{
|
||||||
size_t mx;
|
ptrdiff_t mx;
|
||||||
size_t my;
|
ptrdiff_t my;
|
||||||
vector<char> data;
|
vector<char> data;
|
||||||
|
|
||||||
static size_t check_size(size_t s)
|
static ptrdiff_t check_size(ptrdiff_t size)
|
||||||
{
|
{
|
||||||
// invariant check
|
// invariant check
|
||||||
Expects(s > 0);
|
Expects(size > 0);
|
||||||
return s;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// even more better would be a class for a 2D Size as one single parameter
|
// even better would be a class for a 2D Size as one single parameter
|
||||||
Picture(size_t x, size_t y)
|
Picture(ptrdiff_t x, ptrdiff_t y)
|
||||||
: mx(check_size(x))
|
: mx(check_size(x))
|
||||||
, my(check_size(y))
|
, my(check_size(y))
|
||||||
// now we know x and y have a valid size
|
// now we know x and y have a valid size
|
||||||
|
|||||||
Reference in New Issue
Block a user