Permalink
Browse files

Bugfix: negative integers in raw encoding stream.

Add test. Reported by Tim Caswell.
  • Loading branch information...
1 parent e25afc3 commit 9d3ed1bb9231798df8a081746fd0dc75900d8276 @ry ry committed Jul 31, 2009
Showing with 48 additions and 1 deletion.
  1. +1 −1 src/net.cc
  2. +47 −0 test/mjsunit/test-tcp-raw.js
View
@@ -437,7 +437,7 @@ Connection::OnReceive (const void *buf, size_t len)
// raw encoding
Local<Array> array = Array::New(len);
for (size_t i = 0; i < len; i++) {
- char val = static_cast<const char*>(buf)[i];
+ unsigned char val = static_cast<const unsigned char*>(buf)[i];
array->Set(Integer::New(i), Integer::New(val));
}
argv[0] = array;
@@ -0,0 +1,47 @@
+include("mjsunit.js");
+PORT = 23123;
+
+var echoServer = node.tcp.createServer(function (connection) {
+ connection.addListener("receive", function (chunk) {
+ connection.send(chunk, "raw");
+ });
+ connection.addListener("eof", function () {
+ connection.close();
+ });
+});
+echoServer.listen(PORT);
+
+var recv = [];
+var j = 0;
+
+function onLoad () {
+ var c = node.tcp.createConnection(PORT);
+
+ c.addListener("receive", function (chunk) {
+ if (++j < 256) {
+ c.send([j], "raw");
+ } else {
+ c.close();
+ }
+ for (var i = 0; i < chunk.length; i++) {
+ recv.push(chunk[i]);
+ }
+ });
+
+ c.addListener("connect", function () {
+ c.send([j], "raw");
+ });
+
+ c.addListener("disconnect", function () {
+ p(recv);
+ echoServer.close();
+ });
+};
+
+function onExit () {
+ var expected = [];
+ for (var i = 0; i < 256; i++) {
+ expected.push(i);
+ }
+ assertEquals(expected, recv);
+}

0 comments on commit 9d3ed1b

Please sign in to comment.