From 64341b9adafdd3f47163a7de918d751763a8908e Mon Sep 17 00:00:00 2001 From: Ilya Orlov Date: Mon, 15 Oct 2018 00:27:17 +0300 Subject: [PATCH] common: improve linux snprintf_s implementation (fix wrong processing console text in line_edit_control::add_inserted_text) --- src/Common/PlatformLinux.inl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Common/PlatformLinux.inl b/src/Common/PlatformLinux.inl index 771431b861f..003d4322277 100644 --- a/src/Common/PlatformLinux.inl +++ b/src/Common/PlatformLinux.inl @@ -287,11 +287,27 @@ typedef dirent DirEntryType; #define lstrcpy strcpy #define stricmp strcasecmp #define strupr SDL_strupr -inline bool strncpy_s(char * dest, size_t, const char * source, size_t num) { - return NULL == strncpy(dest, source, num); +inline bool strncpy_s(char * dest, size_t dst_size, const char * source, size_t num) { + bool result = false; + size_t len = 0; + + if((dst_size - 1) >= num) + len = num; + else + len = dst_size - 1; + + result = (NULL == strncpy(dest, source, len)); + dest[len] = 0; + + return result; } inline bool strncpy_s(char * dest, const char * source, size_t num) { - return NULL == strncpy(dest, source, num); + bool result = false; + + result = (NULL == strncpy(dest, source, num)); + dest[num] = 0; + + return result; } inline int strcpy_s(char *dest, const char *source) { return (int)(NULL == strcpy(dest, source)); } inline int strcpy_s(char *dest, size_t num, const char *source) { return (int)(NULL == strcpy(dest, source)); }