Skip to content

bpo-35091: Objects/listobject.c: Don't rely on signed int overflow in…#10184

Closed
izbyshev wants to merge 1 commit intopython:masterfrom
izbyshev:bpo-35091-size_t
Closed

bpo-35091: Objects/listobject.c: Don't rely on signed int overflow in…#10184
izbyshev wants to merge 1 commit intopython:masterfrom
izbyshev:bpo-35091-size_t

Conversation

@izbyshev
Copy link
Copy Markdown
Contributor

@izbyshev izbyshev commented Oct 28, 2018

… gallop functions

Signed integer overflow is undefined behavior. Use unsigned types instead.

https://bugs.python.org/issue35091

… gallop functions

Signed integer overflow is undefined behavior. Use unsigned types instead.
Comment thread Objects/listobject.c
assert(lastofs <= ofs && ofs <= (size_t)n);
/* Now a[lastofs-1] < key <= a[ofs], so key belongs somewhere to the
* right of lastofs-1 but no farther right than ofs. Do a binary
* search, with invariant a[lastofs-1] < key <= a[ofs].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* search, with invariant a[lastofs-1] < key <= a[ofs].
* search, with invariant a[lastofs] < key <= a[ofs].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the first part of the comment, the last line seems to refer to the invariant holding after ++lastofs, which I moved higher. Therefore, no correction is needed.

Comment thread Objects/listobject.c
assert(lastofs <= ofs && ofs <= (size_t)n);
/* Now a[lastofs-1] <= key < a[ofs], so key belongs somewhere to the
* right of lastofs-1 but no farther right than ofs. Do a binary
* search, with invariant a[lastofs-1] <= key < a[ofs].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* search, with invariant a[lastofs-1] <= key < a[ofs].
* search, with invariant a[lastofs] <= key < a[ofs].

@csabella
Copy link
Copy Markdown
Contributor

Merged GH-10202 as the PR approved by @tim-one, so I'll close this one.

@csabella csabella closed this May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants