Ticket #8431: boost_1_53_0_random_device_win32_error_msg.diff

File boost_1_53_0_random_device_win32_error_msg.diff, 1.2 KB (added by frank.richter@…, 10 years ago)

random_device: Improve error reporting on Win32

  • libs/random/src/random_device.cpp

    diff -rub boost_1_53_0.org/libs/random/src/random_device.cpp boost_1_53_0/libs/random/src/random_device.cpp
    old new  
    104110private:
    105111  void error(const std::string & msg) {
    106112    char buf[80];
     113    DWORD error_code (GetLastError());
    107114    DWORD num = FormatMessageA(
    108115      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
    109116      NULL,
    110       GetLastError(),
     117      error_code,
    111118      0,
    112119      buf,
    113120      sizeof(buf),
    114121      NULL);
     122    char hex_error[9];
     123    hex_error[8] = 0;
     124    _snprintf (hex_error, sizeof (hex_error), "%08x", error_code);
    115125
    116126    throw std::invalid_argument("boost::random_device: " + msg +
    117                                 " Cryptopraphic Service Provider " + provider +
    118                                 ": " + std::string(&buf[0], &buf[0] + num));
     127                                ": " + hex_error + " " + std::string(&buf[0], &buf[0] + num) +
     128                                " (Cryptographic Service Provider: " + provider + ")");
    119129  }
    120130  const std::string provider;
    121131  HCRYPTPROV hProv;