Skip to content

gh-96678: A few asserts to demonstrate undefined behaviour in 3.11 #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.11
Choose a base branch
from

Conversation

matthiasgoergens
Copy link
Owner

@matthiasgoergens matthiasgoergens commented Sep 8, 2022

Backported from my asserts for main.

See python#96678

@matthiasgoergens matthiasgoergens changed the title A few asserts to demonstrate undefined behaviour A few asserts to demonstrate undefined behaviour in 3.11 Sep 8, 2022
@matthiasgoergens matthiasgoergens changed the title A few asserts to demonstrate undefined behaviour in 3.11 gh-96678: A few asserts to demonstrate undefined behaviour in 3.11 Sep 8, 2022
@@ -812,11 +812,16 @@ bu_int(_structmodulestate *state, const char *p, const formatdef *f)
Py_ssize_t i = f->size;
const unsigned char *bytes = (const unsigned char *)p;
do {
assert(0 <= x);
assert(x <= (LLONG_MAX>>8));
Copy link
Owner Author

Choose a reason for hiding this comment

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

This one should be LONG_MAX.

@@ -1558,6 +1564,7 @@ audioop_ulaw2lin_impl(PyObject *module, Py_buffer *fragment, int width)

cp = fragment->buf;
for (i = 0; i < fragment->len*width; i += width) {
assert(0 <= st_ulaw2linear16(*cp));
Copy link
Owner Author

Choose a reason for hiding this comment

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

We'd also need to make sure that we don't left-shift the signed int too far.

Here and in the rest of this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant