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 Incorrect conversion between integer types #5626

Conversation

Nanmozhi22
Copy link

No description provided.

@Nanmozhi22 Nanmozhi22 requested a review from a team May 21, 2024 16:41
Copy link

linux-foundation-easycla bot commented May 21, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Nanmozhi22 / name: Nanmozhi AN (1b71b46)

@dmathieu
Copy link
Member

Could you add a test (and sign the CLA) ?

@@ -187,18 +187,20 @@ func parseOTelTraceState(ts string, isSampled bool) (otelTraceState, error) { //
return otts, nil
}

func parseNumber(key string, input string, maximum uint8) (uint8, error) {
// Here`strconv.ParseInt` is used to parse the input string into an integer. The bit size is specified as 8, which is the bit size of `int8`. The parsed value is then checked against the maximum value, and if it's greater, an error is returned. If the parsed value is within the allowed range, it's returned as an `int8` value.
Copy link
Member

Choose a reason for hiding this comment

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

This kind of comment is too verbose imho. There's no need to describe what the method does, reading the code is the best doc.

@brianwarner
Copy link

/easycla

@brianwarner
Copy link

Hi @dmathieu, we've signed the CLA and are configured in EasyCLA to accept anyone who is a member of our public-facing org, but for some reason it's not picking up @Nanmozhi22. I've filed a ticket with support asking for help.

if err != nil {
return maximum + 1, parseError(key, err)
}
if value > uint64(maximum) {
if value > int64(maximum) {

Choose a reason for hiding this comment

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

Comparing int8(value) with int64(maximum) can I know why?

@MrAlias MrAlias added the blocked: CLA Waiting on CLA to be signed before progress can be made label May 28, 2024
Copy link
Contributor

@MadVikingGod MadVikingGod left a comment

Choose a reason for hiding this comment

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

These changes don't effectively make this function any safer and break builds. Therefore, this should not be applied.

func parseNumber(key string, input string, maximum uint8) (uint8, error) {
// Here`strconv.ParseInt` is used to parse the input string into an integer. The bit size is specified as 8, which is the bit size of `int8`. The parsed value is then checked against the maximum value, and if it's greater, an error is returned. If the parsed value is within the allowed range, it's returned as an `int8` value.

func parseNumber(key string, input string, maximum int8) (int8, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change doesn't make sense. The output of this is going to be used as a uint8 anyway, so we are now throwing away half the usable space. This change will break builds that haven't been run.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the response! Do you have any suggestions on how to make it , so that I can try to make those changes

Comment on lines -198 to +203
if value > uint64(maximum) {
if value > int64(maximum) {
return maximum + 1, parseError(key, strconv.ErrRange)
}
return uint8(value), nil
return int8(value), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This comparison will prevent the uint8 conversion from ever overflowing. Furthermore, this is always called with maximum = 62, so we aren't near overflow anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: CLA Waiting on CLA to be signed before progress can be made bug Something isn't working sampler: probability:consistent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect conversion between integer types
7 participants