Skip to content

Commit

Permalink
FIX: corrupted output from trace on Posix systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed May 27, 2023
1 parent f41f7d1 commit d063af7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/s-unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {

/***********************************************************************
**
*/ REBCNT Encode_UTF8(REBYTE *dst, REBINT max, void *src, REBCNT *len, REBFLG uni, REBFLG ccr)
*/ REBCNT Encode_UTF8(REBYTE *dst, REBINT max, void *src, REBLEN *len, REBFLG uni, REBFLG ccr)
/*
** Encode the unicode into UTF8 byte string.
**
Expand All @@ -801,11 +801,17 @@ Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
REBYTE *bs = dst; // save start
REBYTE *bp = (REBYTE*)src;
REBUNI *up = (REBUNI*)src;
REBCNT cnt;
REBLEN cnt;

if (len) cnt = *len;
else {
cnt = (REBCNT)(uni ? wcslen((const wchar_t*)bp) : LEN_BYTES((REBYTE*)bp));
if (uni) {
// not using wcslen, because on some systems wchar_t has 4 bytes!
cnt = 0;
while (*up++ != 0 && cnt < max) cnt++;
up = (REBUNI*)src;
} else
cnt = LEN_BYTES(bp);
}

for (; max > 0 && cnt > 0; cnt--) {
Expand Down Expand Up @@ -833,7 +839,6 @@ Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
}

if (len) *len = dst - bs;

return uni ? up - (REBUNI*)src : bp - (REBYTE*)src;
}

Expand Down

0 comments on commit d063af7

Please sign in to comment.