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

Building a string longer than 127 characters with variable concatenation corrupts the string. #169

Closed
rickmas opened this Issue Jan 31, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@rickmas
Copy link

rickmas commented Jan 31, 2018

TinyCLR 0.7.0

A string variable assigned more than 127 characters through concatenation that includes at least one variable gets corrupted.

For example this code:

            //int v = 123;
            string v = "123";
            //                     1         2         3         4         5         6         7         8         9         0         1         2
            String s0 = $"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678";

            String s1 = $"{v}4567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567";     //Interpolated String
            String s2 = $"{v}45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678";    //Interpolated String

            String s3 = v + "4567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567";     // + concatenation
            String s4 = v + "45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678";    // + concatenation

            String s5 = String.Format("{0}4567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567", v);    //String.Format
            String s6 = String.Format("{0}45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678", v);   //String.Format

shows:

  • s0 with a length longer than 127 characters but no concatenation.
  • s1, s3, s5 demonstrate different methods for concatenation resulting in strings that are 127 characters and have no issue.
  • s2, s4, s6 each have one additional character (128) and all are corrupt. Interestingly though the Length property returns the proper size of 128 even though the string appears corrupted.

Here's a table showing the results:

Name Concatenation Type Length Issue? Resulting Value
s0 None 128 No "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
s1 Interpolation 127 No "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"
s2 Interpolation 128 Yes "@l���"
s3 + 127 No "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"
s4 + 128 Yes "�b���"
s5 String.Format 127 No "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"
s6 String.Format 128 Yes "0_���"

Also, the datatype of the variable used in the concatenation doesn't seem to make any difference. I tried both string and int with the same outcome.

@Arke64

This comment has been minimized.

Copy link
Member

Arke64 commented Jan 31, 2018

We have been able to reproduce the issue using the various Visual Studio inspection tools, but it looks like the variable itself is fine, at least in our tests. When printing out the variable, for example, the contents is correct. Do you see the same behavior?

Debug.WriteLine(s0);
Debug.WriteLine(s1);
Debug.WriteLine(s2);
Debug.WriteLine(s3);
Debug.WriteLine(s4);
Debug.WriteLine(s5);
Debug.WriteLine(s6);

@Arke64 Arke64 added the bug label Jan 31, 2018

@Arke64 Arke64 added this to the v0.8.0 milestone Jan 31, 2018

@rickmas

This comment has been minimized.

Copy link

rickmas commented Jan 31, 2018

Yes, Debug.Writeline() does show the variables properly. I found this issue when throwing an exception with a string built through concatenation and the output was garbled there too.

throw new ApplicationException(s6);

@Arke64 Arke64 closed this Jan 31, 2018

@Arke64

This comment has been minimized.

Copy link
Member

Arke64 commented Jan 31, 2018

For the 0.8 release, we have fixed the string getting corrupt in display. However, it'll be limited to a max of 128 characters displayed. In a future release we will come back and lift that limit.

@rickmas

This comment has been minimized.

Copy link

rickmas commented Jan 31, 2018

Sounds good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment