https://bugzilla.novell.com/show_bug.cgi?id=486234


           Summary: System.String.LastIndexOf(string, StringComparison)
                    crashes when using StringComparison.Ordinal on empty
                    strings
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.4.x
          Platform: PowerPC
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: [email protected]
        ReportedBy: [email protected]
         QAContact: [email protected]
          Found By: ---


Hello,

when LastIndexOf("any text", StringComparison.Ordinal) is invoked on an empty
("") string, it will crash instead of returning -1. The reason for this is that
LastIndexOf(string, StringComparison) calls LastIndexOf(string, this.Length -
1, this.Length, comparisonType). this.Length is 0 => this.Length - 1 = MAXINT.
This makes LastIndexOfOrdinal throw an ArgumentOutOfRangeException (for the
startIndex).

I tried replacing the original call by:
if (this.Length >= 1)
  return LastIndexOf (value, this.Length - 1, this.Length, comparisonType);
else
  return -1;

But strangely, I could not get this to compile (The compiler crashes throwing
exceptions). I'm not sure if this is correct, how should the call behave when
it is invoked on an empty string with an empty string as parameter?
I don't have a Windows system, so I can't check it myself.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
_______________________________________________
mono-bugs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to