From ab616cf3a4b5ed28f2905ea14f11e6a077c98ffa Mon Sep 17 00:00:00 2001 From: Garux Date: Tue, 26 Nov 2024 03:33:39 +0500 Subject: [PATCH] implement string_clone_range without strncpy --- libs/string/string.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/string/string.h b/libs/string/string.h index bbd5ca36..09965e13 100644 --- a/libs/string/string.h +++ b/libs/string/string.h @@ -213,8 +213,8 @@ inline char* string_clone( const char* other, Allocator& allocator ){ /// The returned buffer must be released with \c string_release using a matching \p allocator. template inline char* string_clone_range( StringRange range, Allocator& allocator ){ - char* copied = strncpy( string_new( range.size(), allocator ), range.data(), range.size() ); - copied[range.size()] = '\0'; + char* copied = string_new( range.size(), allocator ); + *std::copy_n( range.data(), range.size(), copied ) = '\0'; return copied; }