aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Bishop <mbtyke@gmail.com>2013-07-18 14:57:57 -0400
committerMichael Bishop <mbtyke@gmail.com>2013-07-18 14:57:57 -0400
commit4962ed9eb8ae7eb76920644e2e39817eac9ad219 (patch)
treecb4e008e8f8d91aefaaac501e2f04a4d5b17ba3d /src
parent646e5af8883c87e4c9b8e709c18fb65520199dc6 (diff)
Fixes in pread()
The bug occurs when pread() doesn't return 0 when asked to read an offset beyond its buffer. This behavior is explicitly documented at: http://pubs.opengroup.org/onlinepubs/000095399/functions/read.html > If the starting position is at or after the end-of-file, 0 > shall be returned
Diffstat (limited to 'src')
-rw-r--r--src/library.js5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/library.js b/src/library.js
index e0db3336..45f3c1e0 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1776,6 +1776,8 @@ LibraryManager.library = {
} else if (nbyte < 0 || offset < 0) {
___setErrNo(ERRNO_CODES.EINVAL);
return -1;
+ } else if (offset >= stream.object.contents.length) {
+ return 0;
} else {
var bytesRead = 0;
while (stream.ungotten.length && nbyte > 0) {
@@ -1785,6 +1787,8 @@ LibraryManager.library = {
}
var contents = stream.object.contents;
var size = Math.min(contents.length - offset, nbyte);
+ assert( size >= 0 );
+
#if USE_TYPED_ARRAYS == 2
if (contents.subarray) { // typed array
HEAPU8.set(contents.subarray(offset, offset+size), buf);
@@ -1852,6 +1856,7 @@ LibraryManager.library = {
} else {
var ungotSize = stream.ungotten.length;
bytesRead = _pread(fildes, buf, nbyte, stream.position);
+ assert( bytesRead >= -1 );
if (bytesRead != -1) {
stream.position += (stream.ungotten.length - ungotSize) + bytesRead;
}