Bugfix: Negative ints in HTTP's on_body and node.fs.read()
authorRyan <ry@tinyclouds.org>
Sun, 9 Aug 2009 16:10:16 +0000 (18:10 +0200)
committerRyan <ry@tinyclouds.org>
Sun, 9 Aug 2009 16:10:16 +0000 (18:10 +0200)
Similar to the error fixed in
9d3ed1bb9231798df8a081746fd0dc75900d8276.

Reported by Felix Geisendörfer.

src/file.cc
src/http.cc

index 368068c..cfabaa9 100644 (file)
@@ -285,7 +285,8 @@ AfterRawRead(eio_req *req)
     size_t len = req->result;
     Local<Array> array = Array::New(len);
     for (unsigned int i = 0; i < len; i++) {
-      array->Set(Integer::New(i), Integer::New(buf[i]));
+      unsigned char val = reinterpret_cast<const unsigned char*>(buf)[i];
+      array->Set(Integer::New(i), Integer::New(val));
     }
     argv[0] = array;
     argv[1] = Integer::New(req->result);
index 945d988..0958b5a 100644 (file)
@@ -196,7 +196,7 @@ HTTPConnection::on_body (http_parser *parser, const char *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 = reinterpret_cast<const unsigned char*>(buf)[i];
       array->Set(Integer::New(i), Integer::New(val));
     }
     argv[0] = array;