Skip to content

Commit

Permalink
Fix encoding of large strings in the soft debugger api. Fixes #648832.
Browse files Browse the repository at this point in the history
  • Loading branch information
vargaz committed Nov 3, 2010
1 parent 339b3f3 commit bc7c3c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 19 additions & 1 deletion mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs
Expand Up @@ -678,32 +678,48 @@ class PacketWriter {
int offset;

public PacketWriter () {
// FIXME:
data = new byte [1024];
offset = 0;
}

void MakeRoom (int size) {
if (offset + size >= data.Length) {
int new_len = data.Length * 2;
while (new_len < offset + size) {
new_len *= 2;
}
byte[] new_data = new byte [new_len];
Array.Copy (data, new_data, data.Length);
data = new_data;
}
}

public PacketWriter WriteByte (byte val) {
MakeRoom (1);
encode_byte (data, val, ref offset);
return this;
}

public PacketWriter WriteInt (int val) {
MakeRoom (4);
encode_int (data, val, ref offset);
return this;
}

public PacketWriter WriteId (long id) {
MakeRoom (8);
encode_id (data, id, ref offset);
return this;
}

public PacketWriter WriteLong (long val) {
MakeRoom (8);
encode_long (data, val, ref offset);
return this;
}

public PacketWriter WriteFloat (float f) {
MakeRoom (8);
byte[] b = DataConverter.GetBytesBE (f);
for (int i = 0; i < 4; ++i)
data [offset + i] = b [i];
Expand All @@ -712,6 +728,7 @@ class PacketWriter {
}

public PacketWriter WriteDouble (double d) {
MakeRoom (8);
byte[] b = DataConverter.GetBytesBE (d);
for (int i = 0; i < 8; ++i)
data [offset + i] = b [i];
Expand All @@ -734,6 +751,7 @@ class PacketWriter {
public PacketWriter WriteString (string s) {
encode_int (data, s.Length, ref offset);
byte[] b = Encoding.UTF8.GetBytes (s);
MakeRoom (b.Length);
Buffer.BlockCopy (b, 0, data, offset, b.Length);
offset += b.Length;
return this;
Expand Down
7 changes: 7 additions & 0 deletions mcs/class/Mono.Debugger.Soft/Test/dtest.cs
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Net;
using System.Reflection;
using System.Text;
using Mono.Cecil.Cil;
using Mono.Debugger.Soft;
using Diag = System.Diagnostics;
Expand Down Expand Up @@ -1654,6 +1655,12 @@ public class DebuggerTests
Assert.AreEqual ("ABC", s.Value);
Assert.AreEqual (vm.RootDomain, s.Domain);

// Long strings
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < 1024; ++i)
sb.Append ('A');
s = vm.RootDomain.CreateString (sb.ToString ());

// Argument checking
AssertThrows <ArgumentNullException> (delegate () {
s = vm.RootDomain.CreateString (null);
Expand Down

0 comments on commit bc7c3c0

Please sign in to comment.