Skip to content

Commit 4e714f1

Browse files
committed
Fix flaws in randomsequence.cpp and randomsequence.h.
- Eliminate SIZE_MAX hack. - Eliminate obsolete include.
1 parent d3c3fd5 commit 4e714f1

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

source/base/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define OFFICIAL_VERSION_STRING "3.7.1"
4646
#define OFFICIAL_VERSION_NUMBER 371
4747

48-
#define POV_RAY_PRERELEASE "alpha.8696519"
48+
#define POV_RAY_PRERELEASE "alpha.8697045"
4949

5050
#if (POV_RAY_IS_AUTOBUILD == 1) && ((POV_RAY_IS_OFFICIAL == 1) || (POV_RAY_IS_SEMI_OFFICIAL == 1))
5151
#ifdef POV_RAY_PRERELEASE

source/core/math/randomsequence.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
#include "core/math/randomsequence.h"
3838

3939
#include <cassert>
40-
#include <stdexcept>
40+
41+
#include <limits>
4142
#include <map>
43+
#include <stdexcept>
4244

4345
#include <boost/random/mersenne_twister.hpp>
4446
#include <boost/random/uniform_int.hpp>
@@ -63,10 +65,6 @@ using boost::uniform_real;
6365
using boost::variate_generator;
6466
using boost::mt19937;
6567

66-
#ifndef SIZE_MAX
67-
#define SIZE_MAX ((size_t)-1)
68-
#endif
69-
7068
#define PRIME_TABLE_COUNT 25
7169
unsigned int primeTable[PRIME_TABLE_COUNT] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 };
7270

@@ -251,7 +249,7 @@ class HybridNumberGenerator : public SeedableNumberGenerator<Type>, public Index
251249
/**
252250
* Template class representing a generator for uniformly distributed numbers in a given range.
253251
*/
254-
template<class Type, class BoostGenerator, class UniformType, size_t CYCLE_LENGTH = SIZE_MAX>
252+
template<class Type, class BoostGenerator, class UniformType, size_t CYCLE_LENGTH = 0>
255253
class UniformRandomNumberGenerator : public SequentialNumberGenerator<Type>
256254
{
257255
public:
@@ -626,7 +624,13 @@ Type UniformRandomNumberGenerator<Type,BoostGenerator,UniformType,CYCLE_LENGTH>:
626624
template<class Type, class BoostGenerator, class UniformType, size_t CYCLE_LENGTH>
627625
size_t UniformRandomNumberGenerator<Type,BoostGenerator,UniformType,CYCLE_LENGTH>::CycleLength() const
628626
{
629-
return CYCLE_LENGTH;
627+
if (CYCLE_LENGTH == 0)
628+
// SIZE_MAX is not mandatory in C++03, and std::numeric_limits<size_t>::max() can't be used
629+
// as a template parameter, so to indicate an "unknown or pretty huge" cycle length we're
630+
// using a template parameter value of 0 instead to convey that information.
631+
return std::numeric_limits<size_t>::max();
632+
else
633+
return CYCLE_LENGTH;
630634
}
631635

632636

@@ -728,9 +732,9 @@ shared_ptr<vector<Type> const> NumberSequenceFactory<Type>::operator()(size_t co
728732
size_t newCount = count;
729733
if (masterSequence->size() > newCount / 2)
730734
{
731-
// make sure to pre-compute at least twice the already-computed size, so we don't waste too much space with
732-
if (masterSequence->size() > SIZE_MAX / 2) // play it safe (though that'll have us run out of memory anyway)
733-
newCount = SIZE_MAX;
735+
// make sure to pre-compute at least twice the already-computed size
736+
if (masterSequence->size() > std::numeric_limits<size_t>::max() / 2) // play it safe (though that'll have us run out of memory anyway)
737+
newCount = std::numeric_limits<size_t>::max();
734738
else
735739
newCount = masterSequence->size() * 2;
736740
}

source/core/math/randomsequence.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
// Module config header file must be the first file included within POV-Ray unit header files
4040
#include "core/configcore.h"
4141

42-
#include <cctype>
4342
#include <vector>
4443

4544
#include "core/math/vector.h"
@@ -131,7 +130,7 @@ class SequentialNumberGenerator
131130
data->push_back((*this)());
132131
return data;
133132
}
134-
/// Returns the number of values after which the generator must be expected to repeat (SIZE_MAX if unknown or pretty huge).
133+
/// Returns the number of values after which the generator must be expected to repeat (maximum size_t value if unknown or pretty huge).
135134
virtual size_t CycleLength() const = 0;
136135
};
137136

unix/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7.1-alpha.8696519
1+
3.7.1-alpha.8697045

0 commit comments

Comments
 (0)