summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-cpp-compiler.h3
-rw-r--r--source/core/slang-random-generator.cpp24
-rw-r--r--source/core/slang-random-generator.h8
-rw-r--r--source/core/slang-visual-studio-compiler-util.cpp9
4 files changed, 39 insertions, 5 deletions
diff --git a/source/core/slang-cpp-compiler.h b/source/core/slang-cpp-compiler.h
index 22c17606a..f1592d240 100644
--- a/source/core/slang-cpp-compiler.h
+++ b/source/core/slang-cpp-compiler.h
@@ -95,7 +95,8 @@ public:
enum Enum : Flags
{
EnableExceptionHandling = 0x01,
- Verbose = 0x02,
+ Verbose = 0x02,
+ EnableSecurityChecks = 0x04,
};
};
diff --git a/source/core/slang-random-generator.cpp b/source/core/slang-random-generator.cpp
index 7e8476c30..ce43067aa 100644
--- a/source/core/slang-random-generator.cpp
+++ b/source/core/slang-random-generator.cpp
@@ -32,15 +32,33 @@ int64_t RandomGenerator::nextInt64()
return (int64_t(high) << 32) | low;
}
-int32_t RandomGenerator::nextInt32InRange(int32_t min, int32_t max)
+uint32_t RandomGenerator::nextUInt32InRange(uint32_t min, uint32_t max)
{
- int32_t diff = max - min;
+ // Make sure max is at least in
+ max = (max >= min) ? max : min;
+
+ // Make 64 bit so can be lazier than having to take care of 32 bit overflow/underflow issues
+ uint32_t diff = max - min;
if (diff <= 1)
{
return min;
}
+ return (nextUInt32() % diff) + min;
+}
- return (nextPositiveInt32() % diff) + min;
+
+int32_t RandomGenerator::nextInt32InRange(int32_t min, int32_t max)
+{
+ // Make sure max is at least in
+ max = (max >= min) ? max : min;
+
+ // Make 64 bit so can be lazier than having to take care of 32 bit overflow/underflow issues
+ uint32_t diff = uint32_t(int64_t(max) - int64_t(min));
+ if (diff <= 1)
+ {
+ return min;
+ }
+ return int32_t(int64_t(nextUInt32() % diff) + min);
}
int64_t RandomGenerator::nextInt64InRange(int64_t min, int64_t max)
diff --git a/source/core/slang-random-generator.h b/source/core/slang-random-generator.h
index 8b4d1759b..57f0e8630 100644
--- a/source/core/slang-random-generator.h
+++ b/source/core/slang-random-generator.h
@@ -30,6 +30,9 @@ class RandomGenerator: public RefObject
/// Get the next bool
virtual bool nextBool();
+ /// Next uint32_t
+ uint32_t nextUInt32() { return uint32_t(nextInt32()); }
+
/// Next Int32 which can only be positive
int32_t nextPositiveInt32() { return nextInt32() & 0x7fffffff; }
/// Next Int64 which can only be positive
@@ -38,9 +41,12 @@ class RandomGenerator: public RefObject
/// Returns value up to BUT NOT INCLUDING maxValue.
int32_t nextInt32UpTo(int32_t maxValue) { assert(maxValue > 0); return (maxValue <= 1) ? 0 : (nextPositiveInt32() % maxValue); }
- /// Returns value from min up to BUT NOT INCLUDING max
+ /// Returns value from min up to BUT NOT INCLUDING max.
int32_t nextInt32InRange(int32_t min, int32_t max);
+ /// Returns value from min up to BUT NOT INCLUDING max
+ uint32_t nextUInt32InRange(uint32_t min, uint32_t max);
+
/// Returns value up to BUT NOT INCLUDING maxValue
int64_t nextInt64UpTo(int64_t maxValue) { assert(maxValue > 0); return (maxValue <= 1) ? 0 : (nextPositiveInt64() % maxValue); }
diff --git a/source/core/slang-visual-studio-compiler-util.cpp b/source/core/slang-visual-studio-compiler-util.cpp
index 48ef108e4..3d0cfdc61 100644
--- a/source/core/slang-visual-studio-compiler-util.cpp
+++ b/source/core/slang-visual-studio-compiler-util.cpp
@@ -95,6 +95,15 @@ namespace Slang
// Doesn't appear to be a VS equivalent
}
+ if (options.flags & CompileOptions::Flag::EnableSecurityChecks)
+ {
+ cmdLine.addArg("/GS");
+ }
+ else
+ {
+ cmdLine.addArg("/GS-");
+ }
+
switch (options.debugInfoType)
{
default: