Avoid uint64 for 32bit compatibility Rather than worry about truncation casting from a possibly 64bit value down to a possibly 32bit size_t we just limit the total bytes per invocation to 4G using an unsigned integer.
Thanks to @seriyps for the report. Fixes #61 Project: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/commit/99867af6 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/tree/99867af6 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/diff/99867af6 Branch: refs/heads/master Commit: 99867af6e9bfec6bb80b10524d4dc27e39150dee Parents: 307c383 Author: Paul J. Davis <[email protected]> Authored: Fri Jun 20 15:30:17 2014 -0500 Committer: Paul J. Davis <[email protected]> Committed: Fri Jun 20 15:30:17 2014 -0500 ---------------------------------------------------------------------- c_src/util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-jiffy/blob/99867af6/c_src/util.c ---------------------------------------------------------------------- diff --git a/c_src/util.c b/c_src/util.c index 5420f81..7436add 100644 --- a/c_src/util.c +++ b/c_src/util.c @@ -31,6 +31,7 @@ get_bytes_per_iter(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpi) jiffy_st* st = (jiffy_st*) enif_priv_data(env); const ERL_NIF_TERM* tuple; int arity; + unsigned int bytes; if(!enif_get_tuple(env, val, &arity, &tuple)) { return 0; @@ -44,10 +45,12 @@ get_bytes_per_iter(ErlNifEnv* env, ERL_NIF_TERM val, size_t* bpi) return 0; } - if(!enif_get_uint64(env, tuple[1], bpi)) { + if(!enif_get_uint(env, tuple[1], &bytes)) { return 0; } + *bpi = (size_t) bytes; + return 1; }
