diff options
Diffstat (limited to 'mcs/class/corlib/System.Text/UTF8Encoding.cs')
-rw-r--r-- | mcs/class/corlib/System.Text/UTF8Encoding.cs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/mcs/class/corlib/System.Text/UTF8Encoding.cs b/mcs/class/corlib/System.Text/UTF8Encoding.cs index fd5e83be04e..bdd80e8a626 100644 --- a/mcs/class/corlib/System.Text/UTF8Encoding.cs +++ b/mcs/class/corlib/System.Text/UTF8Encoding.cs @@ -663,7 +663,7 @@ fail_no_space: throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array")); } - if (charIndex == chars.Length) + if (charIndex == chars.Length && byteCount == 0) return 0; fixed (char* cptr = chars) { @@ -688,10 +688,14 @@ fail_no_space: if (leftOverCount == 0) { int end = byteIndex + byteCount; for (; byteIndex < end; posn++, byteIndex++, byteCount--) { - if (bytes [byteIndex] < 0x80) + if (bytes [byteIndex] < 0x80) { + if (posn >= length) { + throw new ArgumentException (_("Arg_InsufficientSpace"), "chars"); + } chars [posn] = (char) bytes [byteIndex]; - else + } else { break; + } } } |