From b07c3877616c562594dfd3a8cc7c07fed36b8659 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sun, 15 Jan 2023 01:05:13 +0100 Subject: [PATCH] Avoid GCC / Clang warning for literal strings of length SSO::size without terminating \0 character. --- include/tinyutf8/tinyutf8.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/tinyutf8/tinyutf8.h b/include/tinyutf8/tinyutf8.h index 6dfefe3..48cf529 100644 --- a/include/tinyutf8/tinyutf8.h +++ b/include/tinyutf8/tinyutf8.h @@ -1160,7 +1160,10 @@ namespace tiny_utf8 { std::memcpy( t_sso.data , str , LITLEN ); if( str[LITLEN-1] ){ - t_sso.data[LITLEN] = '\0'; + // Note that writing to t_sso.data[SSO::size] is perfectly fine. For strings + // with length SSO::size, the data_len = 0 acts as a terminating '\0' character. + data_type *buffer = t_sso.data; + buffer[LITLEN] = '\0'; set_sso_data_len( LITLEN ); } else