Skip to content

Commit

Permalink
Fix typo and add the error code to the message. Fixes #8431.
Browse files Browse the repository at this point in the history
  • Loading branch information
swatanabe committed Mar 11, 2014
1 parent dc2fdea commit 51ba4a5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/random_device.cpp
Expand Up @@ -111,18 +111,25 @@ class boost::random::random_device::impl
private:
void error(const std::string & msg) {
char buf[80];
DWORD error_code = GetLastError();
DWORD num = FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
error_code,
0,
buf,
sizeof(buf),
NULL);

boost::throw_exception(std::invalid_argument("boost::random_device: " + msg +
" Cryptopraphic Service Provider " + provider +
": " + std::string(&buf[0], &buf[0] + num)));
char hex_error[9];
hex_error[8] = 0;
_snprintf(hex_error, sizeof(hex_error), "%08x", error_code);

boost::throw_exception(
std::invalid_argument(
"boost::random_device: " + msg + ": " + hex_error +
" " + std::string(&buf[0], &buf[0] + num) +
" (Cryptographic Service Provider: " + provider + ")"));
}
const std::string provider;
HCRYPTPROV hProv;
Expand Down

0 comments on commit 51ba4a5

Please sign in to comment.