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

fix undefined conversion #117544

Merged
merged 1 commit into from
May 15, 2023

Conversation

ruquanzhao
Copy link
Member

@ruquanzhao ruquanzhao commented Apr 24, 2023

Signed-off-by: Ruquan Zhao ruquan.zhao@arm.com

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR fixes an uint64(f float64) convertion which is an undefined behavior when the f <= -1.
ref: https://go.dev/ref/spec#Conversions

In this testcase, thinkDuration = -1, which will eventually result in uint(-9.97e+07).

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


Signed-off-by: Ruquan Zhao ruquan.zhao@arm.com
@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 24, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @ruquanzhao. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 24, 2023
@cici37
Copy link
Contributor

cici37 commented Apr 25, 2023

/assign @MikeSpreitzer
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Apr 25, 2023
@MikeSpreitzer
Copy link
Member

I am not sure I understand the point here.

(1) The cited doc does not assert that any numeric conversion is undefined.

(2) The behavior I find in the go playground does not match what I thought the words in the doc meant.

(3) Look at https://go.dev/play/p/_icC51O4TUO . It shows that the proposed change makes no difference.

(4) A floating point value of -9.97e+07 is well within the range that converts to ints with no surprise.

(5) Thanks for catching the typo.

@MikeSpreitzer
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 8, 2023
@ruquanzhao
Copy link
Member Author

@MikeSpreitzer Thanks for your reply!
In cited doc, there is one line:

In all non-constant conversions involving floating-point or complex values, if the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent.

which means something like uint64(-100) is implementation-dependent ( because the value -100 is not in [0,2^63-1] ),
On x86-64, unit64() is implemented just like uint64(int64()), so the playground shows that they are all equal.
On some other arch, uint64() is not implement like x86-64; for example, on arm64, uint64() will return 0 if the floatNum <= -1.
Here is the issue link in golang community golang/go#43047
Below is the output on arm64:

f=-9.97e+07, u1=0 (0x0000000000000000), u2=18446744073609851616 (0xfffffffffa0eb2e0), eq=false
f=-1.844e+19, u1=0 (0x0000000000000000), u2=9223372036854775808 (0x8000000000000000), eq=false
f=-2e+19, u1=0 (0x0000000000000000), u2=9223372036854775808 (0x8000000000000000), eq=false

(4) A floating point value of -9.97e+07 is well within the range that converts to ints with no surprise.

Yes, -9.97e+07 is in range int64 but not in range uint64.

@ruquanzhao
Copy link
Member Author

/retest

@MikeSpreitzer
Copy link
Member

@ruquanzhao : thanks for the clarification and counter-example. I had interpreted those words differently.

Copy link
Member

@MikeSpreitzer MikeSpreitzer left a comment

Choose a reason for hiding this comment

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

/lgtm
Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 15, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: cec22964a09bd09beb75777d4e66a347bc7a2210

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MikeSpreitzer, ruquanzhao

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 15, 2023
@MikeSpreitzer
Copy link
Member

MikeSpreitzer commented May 15, 2023

BTW, typo in the title here: it is spelled "conversion".

@MikeSpreitzer
Copy link
Member

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 15, 2023
@k8s-ci-robot k8s-ci-robot merged commit 4d4d928 into kubernetes:master May 15, 2023
11 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone May 15, 2023
@ruquanzhao ruquanzhao changed the title fix undefined convertion fix undefined conversion May 16, 2023
@ruquanzhao
Copy link
Member Author

TBW, typo in the title here: it is spelled "conversion".

Thanks! BTW

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants