From 99867af6e9bfec6bb80b10524d4dc27e39150dee Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Fri, 20 Jun 2014 15:30:17 -0500 Subject: [PATCH] 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 --- c_src/util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; }