Skip to content

Commit 64341b9

Browse files
committed
common: improve linux snprintf_s implementation (fix wrong processing console text in line_edit_control::add_inserted_text)
1 parent c343424 commit 64341b9

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/Common/PlatformLinux.inl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,27 @@ typedef dirent DirEntryType;
287287
#define lstrcpy strcpy
288288
#define stricmp strcasecmp
289289
#define strupr SDL_strupr
290-
inline bool strncpy_s(char * dest, size_t, const char * source, size_t num) {
291-
return NULL == strncpy(dest, source, num);
290+
inline bool strncpy_s(char * dest, size_t dst_size, const char * source, size_t num) {
291+
bool result = false;
292+
size_t len = 0;
293+
294+
if((dst_size - 1) >= num)
295+
len = num;
296+
else
297+
len = dst_size - 1;
298+
299+
result = (NULL == strncpy(dest, source, len));
300+
dest[len] = 0;
301+
302+
return result;
292303
}
293304
inline bool strncpy_s(char * dest, const char * source, size_t num) {
294-
return NULL == strncpy(dest, source, num);
305+
bool result = false;
306+
307+
result = (NULL == strncpy(dest, source, num));
308+
dest[num] = 0;
309+
310+
return result;
295311
}
296312
inline int strcpy_s(char *dest, const char *source) { return (int)(NULL == strcpy(dest, source)); }
297313
inline int strcpy_s(char *dest, size_t num, const char *source) { return (int)(NULL == strcpy(dest, source)); }

0 commit comments

Comments
 (0)