[Mono-bugs] [Bug 486234] New: System.String.LastIndexOf(string, StringComparison) crashes when using StringComparison.Ordinal on empty strings
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Tue Mar 17 17:45:53 EDT 2009
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: mono-bugs at lists.ximian.com
ReportedBy: jan.pruente at alice-dsl.net
QAContact: mono-bugs at lists.ximian.com
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.
More information about the mono-bugs
mailing list