Skip to content

Commit fa712ed

Browse files
committed
rtlib/dos: write NUL character when DISABLE_WCHAR is used
- ensure NUL terminating character is written on optimized conversion from ascii to wstring in the event that the copy is truncated - for example copying from a larger temporary string to a fixed length wstring and DISABLE_WCHAR is in use (previously HOST_DOS) Conflicts: - changelog.txt, resolved by adding changelog message to 1.10.3 section
1 parent f01e5d6 commit fa712ed

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Version 1.10.3
1111
[fixed]
1212
- github #33: Bi include error in ntdef.bi
1313
- bad code generation of operator cast() UDT ptr passed to byval UDT ptr parameter when matching constructors() are also present
14+
- rtlib/dos: ensure NUL terminating character is written on optimized conversion from ascii to wstring in the event that the copy is truncated - for example copying from a larger temporary string to a fixed length wstring and DISABLE_WCHAR is in use (previously HOST_DOS)
1415

1516

1617
Version 1.10.2

src/rtlib/strw_convfrom_str.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ ssize_t fb_wstr_ConvFromA(FB_WCHAR *dst, ssize_t dst_chars, const char *src)
3737

3838
#if defined HOST_DOS
3939
ssize_t chars = strlen(src);
40-
if (chars > dst_chars)
40+
if (chars > dst_chars) {
4141
chars = dst_chars;
42-
42+
}
4343
memcpy(dst, src, chars + 1);
44+
45+
/* ensure that the null terminator is written, string may have been truncated */
46+
dst[chars] = '\0';
4447
return chars;
4548
#else
4649
/* plus the null-term (note: "n" in chars, not bytes!) */

0 commit comments

Comments
 (0)