Skip to content

Commit

Permalink
i hate c++
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Dec 26, 2023
1 parent c18d2f2 commit 07b8a42
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,20 @@ struct TestContext
int max;
};

void serialize_copy_string( char * dest, const char * source, size_t dest_size )
{
serialize_assert( dest );
serialize_assert( source );
serialize_assert( dest_size >= 1 );
memset( dest, 0, dest_size );
for ( size_t i = 0; i < dest_size - 1; i++ )
{
if ( source[i] == '\0' )
break;
dest[i] = source[i];
}
}

struct TestObject
{
TestData data;
Expand Down Expand Up @@ -2004,8 +2018,7 @@ struct TestObject
for ( int i = 0; i < (int) sizeof( data.bytes ); ++i )
data.bytes[i] = rand() % 255;

memset( data.string, 0, sizeof(data.string) );
strncpy( data.string, "hello world!", sizeof(data.string) - 1 );
serialize_copy_string( data.string, "hello world!", sizeof(data.string) - 1 );
}

template <typename Stream> bool Serialize( Stream & stream )
Expand Down

0 comments on commit 07b8a42

Please sign in to comment.