diff options
author | Michael J. Bishop <mbtyke@gmail.com> | 2013-09-17 13:08:02 -0400 |
---|---|---|
committer | Michael J. Bishop <mbtyke@gmail.com> | 2013-09-17 13:08:02 -0400 |
commit | 8c867e3a4646dadf6922907543103ccf9a11fd75 (patch) | |
tree | ae87d513826db36774618fc9c7c7833f2893c60c /src/library_memfs.js | |
parent | c72022ee3788281dd764782eb51395e322efb1bc (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/library_memfs.js')
-rw-r--r-- | src/library_memfs.js | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/library_memfs.js b/src/library_memfs.js index 354f5e95..28178d9f 100644 --- a/src/library_memfs.js +++ b/src/library_memfs.js @@ -177,7 +177,10 @@ mergeInto(LibraryManager.library, { stream_ops: { read: function(stream, buffer, offset, length, position) { var contents = stream.node.contents; + if (position >= contents.length) + return 0; var size = Math.min(contents.length - position, length); + assert(size >= 0); #if USE_TYPED_ARRAYS == 2 if (size > 8 && contents.subarray) { // non-trivial, and typed array buffer.set(contents.subarray(position, position + size), offset); |