diff --git a/H/YapText.h b/H/YapText.h index 7d5ac5a83..2c5738203 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -190,7 +190,7 @@ INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr, if (rc < 0) { LOCAL_ActiveError->errorNo = REPRESENTATION_ERROR_IN_CHARACTER_CODE; } - return rc; + return rc < 1 ? 1 : rc; } INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr, @@ -202,7 +202,7 @@ INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr, if (rc < 0) { LOCAL_ActiveError->errorNo = REPRESENTATION_ERROR_CHARACTER_CODE; } - return rc; + return rc < 1 ? 1 : rc; } inline static const utf8proc_uint8_t *skip_utf8(const utf8proc_uint8_t *pt, diff --git a/os/format.c b/os/format.c index 1b3faff12..00f40802c 100644 --- a/os/format.c +++ b/os/format.c @@ -277,8 +277,10 @@ static int format_print_str(Int sno, Int size, Int has_size, Term args, const unsigned char *pt = UStringOfTerm(args); while (*pt && (!has_size || size > 0)) { utf8proc_int32_t ch; - pt += get_utf8(pt, -1, &ch); - f_putc(sno, ch); + + if ((pt += get_utf8(pt, -1, &ch)) > 0) { + f_putc(sno, ch); + } } } else { while (!has_size || size > 0) {