Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4af2a18

Browse files
committed
changed strncpy macro to include max sizes for both source and destination.
1 parent 6801256 commit 4af2a18

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/include/tyranscript/tyran_config.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ typedef unsigned short tyran_uint16;
2121
#define tyran_memcmp memcmp
2222

2323
#if defined WIN32
24+
#pragma warning( disable : 4100 )
25+
2426
#define tyran_sscanf sscanf_s
2527
#define tyran_snprintf sprintf_s
26-
#define tyran_strncpy(a, b, c) strncpy_s(a, 1, b, c)
28+
#define tyran_strncpy(dest, dest_size, source, source_size) strncpy_s(dest, dest_size, source, source_size)
2729
#define tyran_fopen fopen_s
2830
#define tyran_fread fread
2931
#define tyran_fclose fclose
3032
#define tyran_strncat strncat_s
3133
#else
3234
#define tyran_sscanf sscanf
3335
#define tyran_snprintf snprintf
34-
#define tyran_strncpy strncpy
36+
#define tyran_strncpy(dest, dest_size, source, source_size) strncpy(dest, source, dest_size)
3537
#define tyran_strncat strncat
3638
#define tyran_fopen(F, N, M) *F = fopen(N, M)
3739
#define tyran_fread fread

src/lib/debug/tyran_print_value.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void tyran_value_to_c_string(const tyran_value* v, char* buf, int max_length, in
4747
if (quote) {
4848
tyran_snprintf(buf, max_length, "'%s'", temp_buffer);
4949
} else {
50-
tyran_strncpy(buf, temp_buffer, temp_buffer_size);
50+
tyran_strncpy(buf, max_length, temp_buffer, temp_buffer_size);
5151
}
5252
break;
5353
case TYRAN_VALUE_TYPE_VARIABLE: {
@@ -152,7 +152,7 @@ void tyran_print_value_helper(int tabs, const char* property, const tyran_value*
152152
default: {
153153
char buf[2048];
154154
tyran_value_to_c_string(v, buf, 2048, quote);
155-
tyran_strncpy(value, buf, max_size);
155+
tyran_strncpy(value, max_size, buf, 2048);
156156
}
157157
break;
158158
}

0 commit comments

Comments
 (0)