Skip to content

Commit 8a69ee2

Browse files
committed
Use memcpy() instead strncpy() to correctly copy NUL bytes
* Such as in UTF-16.
1 parent 854bc8e commit 8a69ee2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/main/c/cext/encoding.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ int rb_tr_enc_mbc_case_fold(rb_encoding *enc, int flag, const UChar** p, const U
362362
p));
363363
int result_len = RSTRING_LEN(result_str);
364364
if (result_len > 0) {
365-
strncpy((char *)result, RSTRING_PTR(result_str), result_len);
365+
memcpy(result, RSTRING_PTR(result_str), result_len);
366366
}
367367
return result_len;
368368
}
@@ -372,7 +372,7 @@ int rb_tr_code_to_mbc(OnigCodePoint code, UChar *buf, OnigEncoding enc) {
372372
rb_tr_unwrap(rb_enc_from_encoding(enc)), code));
373373
int result_len = RSTRING_LEN(result_str);
374374
if (result_len > 0) {
375-
strncpy((char *)buf, RSTRING_PTR(result_str), result_len);
375+
memcpy(buf, RSTRING_PTR(result_str), result_len);
376376
}
377377
return result_len;
378378
}

0 commit comments

Comments
 (0)