From 07b8a4253617cc17b0b917d42ef79e115ebacbb3 Mon Sep 17 00:00:00 2001 From: Glenn Fiedler Date: Tue, 26 Dec 2023 12:42:17 -0500 Subject: [PATCH] i hate c++ --- serialize.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/serialize.h b/serialize.h index 02149a9..086d952 100644 --- a/serialize.h +++ b/serialize.h @@ -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; @@ -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 bool Serialize( Stream & stream )