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

GregorianCalendarHelper, suspicious % operator #78627

Closed
VasilievSerg opened this issue Nov 21, 2022 · 2 comments · Fixed by #78728
Closed

GregorianCalendarHelper, suspicious % operator #78627

VasilievSerg opened this issue Nov 21, 2022 · 2 comments · Fixed by #78728

Comments

@VasilievSerg
Copy link

Link to the sources

public int ToFourDigitYear(int year, int twoDigitYearMax)
{
    if (year < 0)
    {
        throw new ArgumentOutOfRangeException(nameof(year),
            SR.ArgumentOutOfRange_NeedPosNum);
    }

    if (year < 100)
    {
        int y = year % 100; // <=
        return (twoDigitYearMax / 100 - (y > twoDigitYearMax % 100 ? 1 : 0)) * 100 + y;
    }
    ....
}

The y and year variables are always equal.
Since year's value is in range [0, 99], the result of the year % 100 expression is always equal to year.

I'm not sure whether the marked statement is redundant or it is an error.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 21, 2022
@ghost
Copy link

ghost commented Nov 21, 2022

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

Issue Details

Link to the sources

public int ToFourDigitYear(int year, int twoDigitYearMax)
{
    if (year < 0)
    {
        throw new ArgumentOutOfRangeException(nameof(year),
            SR.ArgumentOutOfRange_NeedPosNum);
    }

    if (year < 100)
    {
        int y = year % 100; // <=
        return (twoDigitYearMax / 100 - (y > twoDigitYearMax % 100 ? 1 : 0)) * 100 + y;
    }
    ....
}

The y and year variables are always equal.
Since year's value is in range [0, 99], the result of the year % 100 expression is always equal to year.

I'm not sure whether the marked statement is redundant or it is an error.

Author: VasilievSerg
Assignees: -
Labels:

area-System.Globalization, untriaged

Milestone: -

@stephentoub stephentoub self-assigned this Nov 22, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Nov 22, 2022
@ghost ghost removed in-pr There is an active PR which will close this issue when it is merged untriaged New issue has not been triaged by the area owner labels Nov 24, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants