Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix pread/3 behavior on large size

  • Loading branch information...
commit 3b9e7a9a5c5b4ae83068bc3bf92f54610c0aaa09 1 parent f7a525f
@stolen stolen authored
Showing with 4 additions and 1 deletion.
  1. +4 −1 c_src/emmap.cpp
View
5 c_src/emmap.cpp
@@ -316,9 +316,12 @@ static ERL_NIF_TERM emmap_pread(ErlNifEnv* env, int argc, const ERL_NIF_TERM arg
&& enif_get_ulong(env, argv[2], &bytes)
&& pos >= 0
&& bytes >= 0
- && (pos + bytes) <= handle->len
+ && pos <= handle->len
)
{
+ // Adjust bytes to behave like original file:pread/3
+ if (pos + bytes > handle->len) bytes = handle->len - pos;
+
ErlNifBinary bin;
if ((handle->prot & PROT_READ) == 0) {
Please sign in to comment.
Something went wrong with that request. Please try again.