Skip to content

Commit 6f01c70

Browse files
ArtikashJohelEGP
andauthored
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>
1 parent d2be4cb commit 6f01c70

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

CppCoreGuidelines.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20320,20 +20320,20 @@ and errors (when we didn't deal correctly with semi-constructed objects consiste
2032020320

2032120321
class Picture
2032220322
{
20323-
size_t mx;
20324-
size_t my;
20323+
ptrdiff_t mx;
20324+
ptrdiff_t my;
2032520325
vector<char> data;
2032620326

20327-
static size_t check_size(size_t s)
20327+
static ptrdiff_t check_size(ptrdiff_t size)
2032820328
{
2032920329
// invariant check
20330-
Expects(s > 0);
20331-
return s;
20330+
Expects(size > 0);
20331+
return size;
2033220332
}
2033320333

2033420334
public:
20335-
// even more better would be a class for a 2D Size as one single parameter
20336-
Picture(size_t x, size_t y)
20335+
// even better would be a class for a 2D Size as one single parameter
20336+
Picture(ptrdiff_t x, ptrdiff_t y)
2033720337
: mx(check_size(x))
2033820338
, my(check_size(y))
2033920339
// now we know x and y have a valid size

0 commit comments

Comments
 (0)