Bug - do while loop instead of while loop

5 posts, 0 answers
  1. Volodymyr
    Volodymyr avatar
    2 posts
    Member since:
    May 2011

    Posted 06 May 2011 Link to this post

    Original method:

    public string ToString(int radix)
      {
       if (radix < 2 || radix > 36)
       {
        throw new ArgumentOutOfRangeException("radix");
       }

       if (IsZero)
       {
        return "0";
       }

       BigInteger a = this;
       bool negative = a.IsNegative;
       a = Abs(this);

       BigInteger quotient;
       BigInteger remainder;
       BigInteger biRadix = new BigInteger(radix);

       const string charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
       System.Collections.ArrayList al = new System.Collections.ArrayList();
       while (a._mDigits.DataUsed > 1 || (a._mDigits.DataUsed == 1 && a._mDigits[0] != 0))
       {
        Divide(a, biRadix, out quotient, out remainder);
        al.Insert(0, charSet[(int)remainder._mDigits[0]]);
        a = quotient;
       }

       string result = new String((char[])al.ToArray(typeof(char)));
       if (radix == 10 && negative)
       {
        return "-" + result;
       }

       return result;
      }

    Decompiled method:

    public string ToString(int radix)
    {
    BigInteger bigInteger1 = null;
    BigInteger bigInteger2 = null;
    if (radix < 2 || radix > 36)
    {
    throw new ArgumentOutOfRangeException("radix");
    }
    if (this.IsZero)
    {
    return "0";
    }
    BigInteger bigInteger3 = this;
    bool isNegative = bigInteger3.IsNegative;
    bigInteger3 =
    BigInteger.Abs(this);
    BigInteger bigInteger4 = new BigInteger((long)radix);
    ArrayList arrayLists = new ArrayList();
    do
    {
    BigInteger.Divide(bigInteger3, bigInteger4, out bigInteger1, out bigInteger2);
    arrayLists.
    Insert(0, "0123456789abcdefghijklmnopqrstuvwxyz".get_Chars(bigInteger2._mDigits[0]));
    bigInteger3 = bigInteger1;
    }
    while (bigInteger3._mDigits.DataUsed > 1 || (bigInteger3._mDigits.DataUsed == 1 && bigInteger3._mDigits[0] != 0));
    string str = new string((char[])arrayLists.ToArray(typeof(char)));
    if (radix == 10 && isNegative != 0)
    {
    return string.Concat("-", str);
    }
    return str;
    }

     

     

     

     

     

     

     

  2. Tsviatko Yovtchev
    Admin
    Tsviatko Yovtchev avatar
    408 posts

    Posted 11 May 2011 Link to this post

    Hello Volodymyr,

     Thanks for getting back to us.

    The code in your sample looks logically correct although a bit ugly on the const string part. Is that rhe problem you want to report? OR am I missing something?

    Regards,
    Tsviatko Yovtchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
  4. Volodymyr
    Volodymyr avatar
    2 posts
    Member since:
    May 2011

    Posted 12 May 2011 Link to this post

    Hello again!
    Please see subject - decompiled code has do while loop instead of while loop in original code. And it is bug
  5. Tsviatko Yovtchev
    Admin
    Tsviatko Yovtchev avatar
    408 posts

    Posted 24 May 2011 Link to this post

    Hi Volodymyr,

     My bad, I really missed the title.

    Alright, that is a problem with the correctness of the code. So we have to fix it. Thanks for letting us know about it.

    Kind regards,
    Tsviatko Yovtchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  6. Tsviatko Yovtchev
    Admin
    Tsviatko Yovtchev avatar
    408 posts

    Posted 24 May 2011 Link to this post

    Hi Volodymyr,

     My bad, I really missed the title.

    Alright, that is a problem with the correctness of the code. So we have to fix it. Thanks for letting us know about it.

    Kind regards,
    Tsviatko Yovtchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top
DevCraft banner