Zero-terminate all things we refer to as strings (#1223)

This commit is contained in:
Roy Keene 2019-01-02 16:52:12 -06:00 committed by GitHub
commit 9526f649bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View file

@ -26,7 +26,7 @@ TEST (interface, xrb_uint256_to_string)
TEST (interface, xrb_uint256_to_address)
{
nano::uint256_union zero (0);
char text[65] = { 0 };
char text[66] = { 0 };
xrb_uint256_to_address (zero.bytes.data (), text);
ASSERT_STREQ ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp", text);
}

View file

@ -18,13 +18,13 @@ extern "C" {
void xrb_uint128_to_dec (xrb_uint128 source, char * destination)
{
auto const & number (*reinterpret_cast<nano::uint128_union *> (source));
strncpy (destination, number.to_string_dec ().c_str (), 32);
strncpy (destination, number.to_string_dec ().c_str (), 40);
}
void xrb_uint256_to_string (xrb_uint256 source, char * destination)
{
auto const & number (*reinterpret_cast<nano::uint256_union *> (source));
strncpy (destination, number.to_string ().c_str (), 64);
strncpy (destination, number.to_string ().c_str (), 65);
}
void xrb_uint256_to_address (xrb_uint256 source, char * destination)
@ -36,7 +36,7 @@ void xrb_uint256_to_address (xrb_uint256 source, char * destination)
void xrb_uint512_to_string (xrb_uint512 source, char * destination)
{
auto const & number (*reinterpret_cast<nano::uint512_union *> (source));
strncpy (destination, number.to_string ().c_str (), 128);
strncpy (destination, number.to_string ().c_str (), 129);
}
int xrb_uint128_from_dec (const char * source, xrb_uint128 destination)

View file

@ -10,13 +10,13 @@ typedef unsigned char * xrb_uint256; // 32byte array for public and private keys
typedef unsigned char * xrb_uint512; // 64byte array for signatures
typedef void * xrb_transaction;
// Convert amount bytes 'source' to a 39 byte not-null-terminated decimal string 'destination'
// Convert amount bytes 'source' to a 40 byte null-terminated decimal string 'destination'
void xrb_uint128_to_dec (const xrb_uint128 source, char * destination);
// Convert public/private key bytes 'source' to a 64 byte not-null-terminated hex string 'destination'
// Convert public/private key bytes 'source' to a 65 byte null-terminated hex string 'destination'
void xrb_uint256_to_string (const xrb_uint256 source, char * destination);
// Convert public key bytes 'source' to a 65 byte non-null-terminated account string 'destination'
// Convert public key bytes 'source' to a 66 byte non-null-terminated account string 'destination'
void xrb_uint256_to_address (xrb_uint256 source, char * destination);
// Convert public/private key bytes 'source' to a 128 byte not-null-terminated hex string 'destination'
// Convert public/private key bytes 'source' to a 129 byte null-terminated hex string 'destination'
void xrb_uint512_to_string (const xrb_uint512 source, char * destination);
// Convert 39 byte decimal string 'source' to a byte array 'destination'