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

.net 5.0 seems to be wrong in detecting zero-terminzted string #45912

Closed
vsfeedback opened this issue Dec 10, 2020 · 8 comments
Closed

.net 5.0 seems to be wrong in detecting zero-terminzted string #45912

vsfeedback opened this issue Dec 10, 2020 · 8 comments

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] [regression] [worked-in:16.7]
The following code:

     class Program
     {
         static void Main(string[] args)
         {
             const string s = "abc";
             const string sz = "abc\0";
    
void Report(string str) 
                 => Console.WriteLine($"\"{str}\" ({str. Length}), zero-terminated: {str. EndsWith("\0")}");
    
Report(s);
             Report(sz);
         }
     }

gives the following output for target framework .net 5.0:

"abc" (3), zero-terminated: True
"abc" (4), zero-terminated: True

For target framework .netcoreapp3.1 the code outputs the following lines:

"abc" (3), zero-terminated: False
"abc" (4), zero-terminated: True

As for me, .net core 3.1 behavior looks correct and .net 5.0 does not.


Original Comments

Feedback Bot on 12/9/2020, 10:13 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

@Dotnet-GitSync-Bot
Copy link
Collaborator

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.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Dec 10, 2020
@danmoseley
Copy link
Member

@safern, the repro goes away if I set DOTNET_SYSTEM_GLOBALIZATION_USENLS=1

Did we discuss this case already?

@ghost
Copy link

ghost commented Dec 10, 2020

Tagging subscribers to this area: @tarekgh, @safern, @krwq
See info in area-owners.md if you want to be subscribed.

Issue Details

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] [regression] [worked-in:16.7]
The following code:

     class Program
     {
         static void Main(string[] args)
         {
             const string s = "abc";
             const string sz = "abc\0";
    
void Report(string str) 
                 => Console.WriteLine($"\"{str}\" ({str. Length}), zero-terminated: {str. EndsWith("\0")}");
    
Report(s);
             Report(sz);
         }
     }

gives the following output for target framework .net 5.0:

"abc" (3), zero-terminated: True
"abc" (4), zero-terminated: True

For target framework .netcoreapp3.1 the code outputs the following lines:

"abc" (3), zero-terminated: False
"abc" (4), zero-terminated: True

As for me, .net core 3.1 behavior looks correct and .net 5.0 does not.


Original Comments

Feedback Bot on 12/9/2020, 10:13 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

Author: vsfeedback
Assignees: -
Labels:

area-System.Globalization, area-System.Runtime, untriaged

Milestone: -

@GrabYourPitchforks
Copy link
Member

This behavior is by design. EndsWith(string) is linguistic (culture-aware), and the null character has zero weight under ICU. Caller almost certainly meant to perform an ordinal comparison via EndsWith(char) or EndsWith(..., StringComparison.Ordinal).

@safern
Copy link
Member

safern commented Dec 10, 2020

Thanks, @GrabYourPitchforks you beat me to it.

@tarekgh tarekgh removed the untriaged New issue has not been triaged by the area owner label Dec 10, 2020
@tarekgh
Copy link
Member

tarekgh commented Dec 10, 2020

@GrabYourPitchforks is right. For such operation ordinal comparison has to be used. Also why need to use EndsWith at all? why not just testing str[str.Length - 1] == `\0' ?

@tarekgh tarekgh closed this as completed Dec 10, 2020
@GrabYourPitchforks
Copy link
Member

To be fair, EndsWith is more readable. And it works with empty strings. :)

@tarekgh
Copy link
Member

tarekgh commented Dec 10, 2020

To be fair, EndsWith is more readable. And it works with empty strings. :)

That is a good point. but do you consider the empty string is null terminated or not? for such user scenarios, it should be true I guess.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants