fixed (char* dest = tmp, src = this) {
char* padPos = dest;
- char* padTo = dest + (totalWidth - length);
+ char* padTo;
+ try {
+ padTo = checked (dest + (totalWidth - length));
+ } catch (OverflowException) {
+ throw new OutOfMemoryException ();
+ }
+
while (padPos != padTo)
*padPos++ = paddingChar;
fixed (char* dest = tmp, src = this) {
CharCopy (dest, src, length);
- char* padPos = dest + length;
- char* padTo = dest + totalWidth;
- while (padPos != padTo)
- *padPos++ = paddingChar;
+ try {
+ char* padPos = checked (dest + length);
+ char* padTo = checked (dest + totalWidth);
+ while (padPos != padTo)
+ *padPos++ = paddingChar;
+ } catch (OverflowException) {
+ throw new OutOfMemoryException ();
+ }
}
return tmp;
}
}
}
+ [Test]
+ public void PadLeft_Overflow ()
+ {
+ try {
+ "x".PadLeft (int.MaxValue, '-');
+ } catch (OutOfMemoryException) {
+ }
+ }
+
[Test] // PadRight (Int32)
public void PadRight1 ()
{
Assert.AreEqual ("000000000000", "".PadRight (12, '0'), "#2");
}
+ [Test]
+ public void PadRight_Overflow ()
+ {
+ try {
+ "x".PadRight (int.MaxValue, '-');
+ } catch (OutOfMemoryException) {
+ }
+ }
+
[Test] // Remove (Int32, Int32)
public void Remove2 ()
{