commit 561a75c771f3ac33385f1a0069608c4b99e4585d
parent ea1c18cba367ece0e2de1ac01ddfce28e7c02b53
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 4 Jul 2017 15:20:19 +0200
Fix a wrong cast in ssp_rng_set internals.
Depending on the RNG type, it could lead to truncate the provided seed
to 32 bits.
Fix some typos too.
Diffstat:
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/ssp_rng.c b/src/ssp_rng.c
@@ -196,7 +196,7 @@ rng_cxx_set(void* data, const uint64_t seed)
{
RNG* rng = (RNG*)data;
ASSERT(rng);
- rng->seed((unsigned long)seed);
+ rng->seed((typename RNG::result_type)seed);
return RES_OK;
}
@@ -377,6 +377,7 @@ res_T
rng_cxx_init<aes_T>(struct mem_allocator* allocator, void* data)
{
(void) allocator;
+
if (!haveAESNI()) {
/* AES-NI instructions not available on this hardware */
return RES_BAD_OP;
@@ -572,7 +573,7 @@ ssp_rng_canonical(struct ssp_rng* rng)
return RAN_NAMESPACE::generate_canonical
<double, std::numeric_limits<double>::digits>(rng_cxx);
#else
- /* Optimize version */
+ /* Optimized version */
size_t k = rng->dbl_k;
double sum = 0;
double tmp = 1;
@@ -588,17 +589,17 @@ float
ssp_rng_canonical_float(struct ssp_rng* rng)
{
if(!rng) FATAL("The Random Number Generator is NULL\n");
- rng_cxx rng_cxx(*rng);
/* The C++ standard library does not ensure that the generated single
* precision floating point number is effectively canonical, i.e. it may be
* equal to 1. Use a hand made workaround to handle this bug. */
#if 0
+ rng_cxx rng_cxx(*rng);
return RAN_NAMESPACE::generate_canonical
<float, std::numeric_limits<float>::digits>(rng_cxx);
#else
float r;
do {
- /* Optimise version of the generate_canonical function */
+ /* Optimised version of the generate_canonical function */
size_t k = rng->flt_k;
float sum = 0;
float tmp = 1;