mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
Fixed output of BigNumber::AsByteArray when generated array is shorter than requested size thx Shauren
This commit is contained in:
parent
c8d020c7ea
commit
c604fd3cc8
1 changed files with 6 additions and 9 deletions
|
|
@ -198,23 +198,20 @@ uint8* BigNumber::AsByteArray(int minSize)
|
|||
|
||||
uint8 *BigNumber::AsByteArray(int minSize, bool reverse)
|
||||
{
|
||||
int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes();
|
||||
int numBytes = GetNumBytes();
|
||||
int length = (minSize >= numBytes) ? minSize : numBytes;
|
||||
|
||||
if (_array)
|
||||
{
|
||||
delete[] _array;
|
||||
_array = NULL;
|
||||
}
|
||||
delete[] _array;
|
||||
_array = new uint8[length];
|
||||
|
||||
// If we need more bytes than length of BigNumber set the rest to 0
|
||||
if (length > GetNumBytes())
|
||||
if (length > numBytes)
|
||||
memset((void*)_array, 0, length);
|
||||
|
||||
BN_bn2bin(_bn, (unsigned char *)_array);
|
||||
BN_bn2bin(_bn, (unsigned char*)_array);
|
||||
|
||||
if (reverse)
|
||||
std::reverse(_array, _array + length);
|
||||
std::reverse(_array, _array + numBytes);
|
||||
|
||||
return _array;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue