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:
Akash Mozumdar 2020-03-26 12:38:07 -06:00 committed by GitHub
parent d2be4cba57
commit 6f01c706a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20320,20 +20320,20 @@ and errors (when we didn't deal correctly with semi-constructed objects consiste
class Picture
{
size_t mx;
size_t my;
ptrdiff_t mx;
ptrdiff_t my;
vector<char> data;
static size_t check_size(size_t s)
static ptrdiff_t check_size(ptrdiff_t size)
{
// invariant check
Expects(s > 0);
return s;
Expects(size > 0);
return size;
}
public:
// even more better would be a class for a 2D Size as one single parameter
Picture(size_t x, size_t y)
// even better would be a class for a 2D Size as one single parameter
Picture(ptrdiff_t x, ptrdiff_t y)
: mx(check_size(x))
, my(check_size(y))
// now we know x and y have a valid size