Skip to content
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

MAINT: improved overflow check to avoid undefined behavior #21658

Merged
merged 3 commits into from
Jun 3, 2022

Conversation

Micky774
Copy link
Contributor

@Micky774 Micky774 commented Jun 3, 2022

Related Issues/PRs

Related to #21648

Changes

  • Adds NAME template to @name@_ctype_divide
  • Changes part of overflow check from a == -a to a == NPY_MIN_@NAME@

Comments

The old behavior was pointed out to be undefined, see: #21648 (comment))

@seberg
Copy link
Member

seberg commented Jun 3, 2022

I am not sure that this is bad, but feel that it can't hurt (except that it may create a merge conflict for @ganesh-k13's PR ;)).

Thanks for this "detour", @Micky774!

@seberg seberg merged commit 0435145 into numpy:main Jun 3, 2022
@Micky774 Micky774 deleted the safe_overflow_check branch June 3, 2022 23:00
@@ -164,7 +166,7 @@ static NPY_INLINE int
return NPY_FPE_DIVIDEBYZERO;
}
#if @neg@
else if (b == -1 && a < 0 && a == -a) {
else if (b == -1 && a == NPY_MIN_@NAME@) {
*out = a / b;
Copy link
Member

Choose a reason for hiding this comment

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

@seberg this leads to arithmetic exception yeah?

Thread 1 "python3.10" received signal SIGFPE, Arithmetic exception.
0x00007ffff6f9d7e0 in int_ctype_divide (out=<synthetic pointer>, b=-1, a=-2147483648) at numpy/core/src/umath/scalarmath.c.src:179
179             *out = a / b;

Why do we allow a / b when its a guarantee overflow. ref: #21507

Copy link
Member

Choose a reason for hiding this comment

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

My bad, I guess... you are right, this is nonsense, we took a bad turn somewhere here :/. Are you including the fix in your PR?

Copy link
Member

Choose a reason for hiding this comment

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

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.

None yet

3 participants