From 3db8a92c7ebb057574b65ac7ce041319da5d59a0 Mon Sep 17 00:00:00 2001 From: Doug Hogan Date: Sat, 5 Jan 2019 13:40:05 -0800 Subject: Revamp CONSUME_REDS() --- lib/crypto/c_src/openssl_config.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/crypto/c_src/openssl_config.h b/lib/crypto/c_src/openssl_config.h index e41d0c945e..7ea8c320ae 100644 --- a/lib/crypto/c_src/openssl_config.h +++ b/lib/crypto/c_src/openssl_config.h @@ -308,11 +308,16 @@ #define MAX_BYTES_TO_NIF 20000 #define CONSUME_REDS(NifEnv, Ibin) \ -do { \ - int _cost = ((Ibin).size * 100) / MAX_BYTES_TO_NIF;\ +do { \ + size_t _cost = (Ibin).size; \ + if (_cost > SIZE_MAX / 100) \ + _cost = 100; \ + else \ + _cost = (_cost * 100) / MAX_BYTES_TO_NIF; \ + \ if (_cost) { \ (void) enif_consume_timeslice((NifEnv), \ - (_cost > 100) ? 100 : _cost); \ + (_cost > 100) ? 100 : (int)_cost); \ } \ } while (0) -- cgit v1.2.3