From f2aaa85cca144827af29f0f32df9b1b67cc4aad4 Mon Sep 17 00:00:00 2001
From: Egor Tensin <Egor.Tensin@gmail.com>
Date: Wed, 15 Jan 2020 02:03:28 +0300
Subject: mingw builds: workaround incorrect SymLoadModule64

---
 src/dbghelp.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/dbghelp.cpp b/src/dbghelp.cpp
index eba887e..94fa7ab 100644
--- a/src/dbghelp.cpp
+++ b/src/dbghelp.cpp
@@ -14,6 +14,7 @@
 #include <cstring>
 #include <stdexcept>
 #include <string>
+#include <vector>
 
 namespace pdb {
 namespace {
@@ -73,11 +74,18 @@ void DbgHelp::close() {
 
 ModuleInfo DbgHelp::load_pdb(const std::string& path) const {
     DWORD size = 0;
+
     if (!SafeCast(file::get_size(path), size))
         throw std::range_error{"PDB file is too large"};
 
+    // MinGW-w64 (as of version 7.0) requires PSTR as the third argument.
+    std::vector<char> _path;
+    _path.reserve(path.length() + 1);
+    _path.assign(path.cbegin(), path.cend());
+    _path.emplace_back('\0');
+
     const auto offline_base =
-        SymLoadModule64(id, NULL, path.c_str(), NULL, gen_next_offline_base(size), size);
+        SymLoadModule64(id, NULL, _path.data(), NULL, gen_next_offline_base(size), size);
 
     if (!offline_base)
         throw error::windows(GetLastError());
-- 
cgit v1.2.3