Ticket #51 (new defect)

Opened 11 months ago

Osc.cs:PadSize is computed in a wrong way resulting in badly formatted messages

Reported by: joreg Owned by:
Priority: blocker Milestone:
Component: .NET C# library Keywords:
Cc:

Description

my suggestion for the implementation of PadSize? is:

private static int PadSize(int rawSize)
{
   return rawSize + 4 - rawSize % 4;
}

it is then important to not include the ending \0 in rawSize for 0-terminated strings. this is simple because for strings you can simply call PadSize?(string.length()).

the current implementation somehow leads to problems when sending messages with 3, 7, 11,...parameters as padsize seems to be computed wrong when called with strings of lengths of multiples of 4 (in this case the typetag string e.g: ,iii or ,iiiffff)

also a similar change is necessary in InsertString?. my suggestion:

private static int InsertString(string s, byte[] packet, int start, int length)
{
  int index = start;
  foreach (char c in s)
  {
    packet[index++] = (byte)c;
    if (index == length)
      return index;
  }

  int pad = 4 - (s.Length) % 4;
  while (pad-- > 0)
    packet[index++] = 0;

  return index;
}

attached is a version of Osc.cs that works for me so far.

Attachments

Osc.cs (28.1 KB) - added by joreg 11 months ago.

Change History

Changed 11 months ago by joreg

Note: See TracTickets for help on using tickets.