fix some none portable code that was using GCC impl details

pull/2045/head
Rachel Powers 2023-03-26 00:14:54 -07:00
parent 38426a0075
commit 18fdffdf17
2 changed files with 10 additions and 2 deletions

View File

@ -68,10 +68,18 @@ void DHKeyExchange::init(const unsigned char* prime, size_t primeBits,
generator_ = n(gen.c_str(), gen.length());
size_t pbytes = (privateKeyBits + 7) / 8;
#if defined(_MSC_VER)
// MSVC will not compile dynamic arrays
unsigned char* buf = new unsigned char[pbytes];
#else
unsigned char buf[pbytes];
#endif
util::generateRandomData(buf, pbytes);
privateKey_ = n(reinterpret_cast<char*>(buf), pbytes);
#if defined(_MSC_VER)
// clean up memory
delete[] buf;
#endif
keyLength_ = (primeBits + 7) / 8;
}

View File

@ -51,7 +51,7 @@ SocketRecvBuffer::~SocketRecvBuffer() = default;
ssize_t SocketRecvBuffer::recv()
{
size_t n = std::end(buf_) - last_;
size_t n = (buf_.data() + 16_k) - last_;
if (n == 0) {
A2_LOG_DEBUG("Buffer full");
return 0;