Permalink
Browse files

Fix a length assertion in serialize_string_internal

This fixes an assertion hit when serializing a perfectly valid string like this:

char cool[5] = { 'c', 'o', 'o', 'l', '\0' };
serialize_string(stream, cool, sizeof(cool));

If we'd check that the length < buffer_size - 1,
we'd need to put the '\0' a byte earlier, like so:

char cool[5] = { 'c', 'o', 'o', '\0', '\0' };

Which necessarily wastes a single byte of our buffer.
  • Loading branch information...
geneotech committed Dec 17, 2018
1 parent ffec5ec commit c285f2ac33e33bfdab722c6a620dd1acc59fb5bd
Showing with 1 addition and 1 deletion.
  1. +1 −1 yojimbo.h
@@ -2965,7 +2965,7 @@ namespace yojimbo
if ( Stream::IsWriting )
{
length = (int) strlen( string );
yojimbo_assert( length < buffer_size - 1 );
yojimbo_assert( length < buffer_size );
}
serialize_int( stream, length, 0, buffer_size - 1 );
serialize_bytes( stream, (uint8_t*)string, length );

0 comments on commit c285f2a

Please sign in to comment.