Skip to content

Suspicious StringBuilder using #3457

Closed
Closed

Description

Hi.
Please look this code fragment:

  1. var allErrors = new StringBuilder('\n');
 var allErrors = new StringBuilder('\n');

StringBuilder constructor with a char argument constructs a string with no characters in it ( this argument specified initial capacity) .

You may see example - http://ideone.com/1pPHlZ
I hope this may help you

These possible defects found with AppChecker

Activity

  1. iSazonov commented on Mar 30, 2017

    @iSazonov
    Collaborator

    appchecker (@AppChecker) Thanks for your report!

    I cannot repo the bug:

    using namespace System.Text
    $sb = New-Object StringBuilder('[')
    $sb.Append('a')
    $sb.Append(' ')
    $sb.Append('b')
    $sb.Append(']')
    $sb.ToString()
    
    [a b]
  2. added
    Issue-Question
    on Mar 30, 2017
  3. iSazonov commented on Mar 30, 2017

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) The init post contains link on site (https: //cnpo.ru) with invalid certificate. Should we remove the link?

  4. AppChecker commented on Mar 30, 2017

    @AppChecker
    Author

    Ilya (@iSazonov) Hi! Creating StringBuilder with char argument is work for powershell script, but not work for C#-code: http://ideone.com/1pPHlZ
    P.S. I've updated link with valid certificate

  5. added
    Issue-Bug
    and removed
    Issue-Question
    on Mar 30, 2017
  6. SteveL-MSFT commented on Mar 30, 2017

    @SteveL-MSFT
    Member

    appchecker (@AppChecker) thanks for the bug report, I was able to repro:

    PS C:\Users\slee\repos\PowerShell> Add-Type @"
    >> using System.Text;
    >> public class Test
    >> {
    >>   public static string Foo()
    >>   {
    >>     StringBuilder sb = new StringBuilder('[');
    >>     sb.Append('a');
    >>     sb.Append(' ');
    >>     sb.Append('b');
    >>     sb.Append(']');
    >>     return sb.ToString();
    >>   }
    >> }
    >> "@
    PS C:\Users\slee\repos\PowerShell> [Test]::Foo()
    a b]
  7. iSazonov commented on Mar 30, 2017

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Sorry, I lost my post about that I was able to repro too and pushed fix.

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

Metadata

Metadata

Labels

Issue-BugResolution-Fixed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions