aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/utils
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2017-05-19 06:48:22 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2017-05-19 06:48:22 +0300
commitd48f6281af49b17d1f6d6802b8921c1aed38a713 (patch)
treeeb57744f1eb8a1e414b9b3ea9237156430acd83c /src/utils
parentrefactoring (diff)
downloadwinapi-debug-d48f6281af49b17d1f6d6802b8921c1aed38a713.tar.gz
winapi-debug-d48f6281af49b17d1f6d6802b8921c1aed38a713.zip
hardening & refactoring
My latest obsession is integer overflows.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/file.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/utils/file.cpp b/src/utils/file.cpp
index 4150685..f013d90 100644
--- a/src/utils/file.cpp
+++ b/src/utils/file.cpp
@@ -37,15 +37,12 @@ namespace pdb
if (!GetFileSizeEx(handle.get(), &size))
throw error::windows(GetLastError());
- try
- {
- const msl::utilities::SafeInt<decltype(size.QuadPart)> safe_size{size.QuadPart};
- return static_cast<std::size_t>(safe_size);
- }
- catch (const msl::utilities::SafeIntException&)
- {
- throw std::range_error{"invalid file size"};
- }
+ std::size_t result = 0;
+
+ if (!msl::utilities::SafeCast(size.QuadPart, result))
+ throw std::runtime_error{"unsupported file size"};
+
+ return result;
}
}
}