diff options
author | worktycho <work.tycho@gmail.com> | 2015-05-30 11:32:35 +0200 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2015-05-30 11:32:35 +0200 |
commit | 2ce405883ac34f3f2e443d60ba93a94568568f39 (patch) | |
tree | 63de5aa4fdcfe13224e954aa557096a720389401 /src | |
parent | Merge pull request #2167 from SafwatHalaby/diags (diff) | |
parent | Fix FreeBSD/clang errors caused by -Werror (diff) | |
download | cuberite-2ce405883ac34f3f2e443d60ba93a94568568f39.tar cuberite-2ce405883ac34f3f2e443d60ba93a94568568f39.tar.gz cuberite-2ce405883ac34f3f2e443d60ba93a94568568f39.tar.bz2 cuberite-2ce405883ac34f3f2e443d60ba93a94568568f39.tar.lz cuberite-2ce405883ac34f3f2e443d60ba93a94568568f39.tar.xz cuberite-2ce405883ac34f3f2e443d60ba93a94568568f39.tar.zst cuberite-2ce405883ac34f3f2e443d60ba93a94568568f39.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/Generating/FinishGen.cpp | 6 | ||||
-rw-r--r-- | src/OSSupport/StackTrace.cpp | 9 | ||||
-rw-r--r-- | src/StringUtils.h | 6 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 5540f80d4..656dc95db 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1375,8 +1375,12 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) return mtInvalidType; } - size_t RandMob = static_cast<size_t>((m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)) % ListOfSpawnables.size(); auto MobIter = ListOfSpawnables.begin(); + using diff_type = + std::iterator_traits<decltype(MobIter)>::difference_type; + diff_type RandMob = static_cast<diff_type> + ((unsigned long)(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) + % ListOfSpawnables.size()); std::advance(MobIter, RandMob); return *MobIter; diff --git a/src/OSSupport/StackTrace.cpp b/src/OSSupport/StackTrace.cpp index 015a53ba0..1ec10f20e 100644 --- a/src/OSSupport/StackTrace.cpp +++ b/src/OSSupport/StackTrace.cpp @@ -12,6 +12,13 @@ #include <unistd.h> #endif +// FreeBSD uses size_t for the return type of backtrace() +#if defined(__FreeBSD__) && (__FreeBSD__ >= 10) + #define btsize size_t +#else + #define btsize int +#endif + @@ -34,7 +41,7 @@ void PrintStackTrace(void) // Use the backtrace() function to get and output the stackTrace: // Code adapted from http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes void * stackTrace[30]; - int numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace)); + btsize numItems = backtrace(stackTrace, ARRAYCOUNT(stackTrace)); backtrace_symbols_fd(stackTrace, numItems, STDERR_FILENO); #endif } diff --git a/src/StringUtils.h b/src/StringUtils.h index 8f67d8031..62767d007 100644 --- a/src/StringUtils.h +++ b/src/StringUtils.h @@ -168,6 +168,12 @@ bool StringToInteger(const AString & a_str, T & a_Num) } else { + // Unsigned result cannot be signed! + if (!std::numeric_limits<T>::is_signed) + { + return false; + } + for (size_t size = a_str.size(); i < size; i++) { if ((a_str[i] < '0') || (a_str[i] > '9')) |