diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:23:19 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:23:19 +0200 |
commit | 0887aee8c54d0ed51bb2031431e2bcdafebb4c6e (patch) | |
tree | 69537ceb9787bb25ac363cc4e6cdaf0804d78363 /structures.cpp | |
parent | 5.12 (diff) | |
download | FreeFileSync-0887aee8c54d0ed51bb2031431e2bcdafebb4c6e.tar.gz FreeFileSync-0887aee8c54d0ed51bb2031431e2bcdafebb4c6e.tar.bz2 FreeFileSync-0887aee8c54d0ed51bb2031431e2bcdafebb4c6e.zip |
5.13
Diffstat (limited to 'structures.cpp')
-rw-r--r-- | structures.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/structures.cpp b/structures.cpp index 54db613c..76dec74e 100644 --- a/structures.cpp +++ b/structures.cpp @@ -280,7 +280,8 @@ Int64 resolve(size_t value, UnitTime unit, Int64 defaultVal) UInt64 resolve(size_t value, UnitSize unit, UInt64 defaultVal) { - double out = 0; + const UInt64 maxVal =std::numeric_limits<zen::UInt64>::max(); + switch (unit) { case USIZE_NONE: @@ -288,15 +289,14 @@ UInt64 resolve(size_t value, UnitSize unit, UInt64 defaultVal) case USIZE_BYTE: return value; case USIZE_KB: - out = 1024.0 * value; - break; + return value > maxVal / 1024U ? maxVal : //prevent overflow!!! + 1024U * value; case USIZE_MB: - out = 1024 * 1024.0 * value; - break; + return value > maxVal / (1024 * 1024U) ? maxVal : //prevent overflow!!! + 1024 * 1024U * value; } - return out >= to<double>(std::numeric_limits<zen::UInt64>::max()) ? //prevent overflow!!! - std::numeric_limits<zen::UInt64>::max() : - zen::UInt64(out); + assert(false); + return defaultVal; } } |