Commit 3759a85a authored by Jonathan Michalon's avatar Jonathan Michalon

libovcc: allow zero-length payload messages (ie. empty Variant array)

parent 254e8562
......@@ -148,14 +148,18 @@ namespace OVCC.Network
throws Error
{
var len = stream.read_uint16 (cancel);
if (len < 1 || len > 0x4000 /* arbitrary limit not to fulfill memory */) {
if (len < 0 || len > 0x4000 /* arbitrary limit not to fulfill memory */) {
throw new MessageError.MALFORMED_MESSAGE ("Invalid message length %u",
len);
}
var buf = new uint8[len];
stream.read (buf, cancel);
return buf;
if (len > 0) {
var buf = new uint8[len];
stream.read (buf, cancel);
return buf;
} else {
return null;
  • apparently this works, but wouldn't it be more natural to still do new uint8[len]?

    var buf = new uint8[len];
    
    if (len > 0) {
      stream.read (buf, cancel);
    }
    
    return buf;
  • yeah and in fact triggers a warning; fixed as part of edcab86f

  • I'd still rather see a code with the least amount of duplication in the conditionals, but good.

  • hum that code changed even later so yeah now we have a new uint on both conditions… Let's write this and that's it…

          var buf = new uint8[len];
          if (len > 0) {
            stream.read (buf, cancel);
          }
          return buf;
    Edited by Jonathan Michalon
  • Looks similar to my suggestion above :)

Please register or sign in to reply
}
}
protected bool write_buffer (DataOutputStream stream,
......@@ -164,7 +168,11 @@ namespace OVCC.Network
throws Error
{
stream.put_uint16 ((uint16)buf.length, cancel);
return stream.write (buf, cancel) == buf.length;
if (buf.length > 0) {
return stream.write (buf, cancel) == buf.length;
} else {
return true;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment