From fb8bef86d52371518ce39caf9dde742e5958e90d Mon Sep 17 00:00:00 2001 From: fef Date: Tue, 9 Nov 2021 22:16:35 +0100 Subject: [PATCH] kprintf: explicitly disable wchar support This might get implemented later, even though there is no real reason why we would need wchar support in the kernel as it is UTF-8 native --- kernel/kprintf.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/kernel/kprintf.c b/kernel/kprintf.c index 16fc909..fae848e 100644 --- a/kernel/kprintf.c +++ b/kernel/kprintf.c @@ -312,17 +312,12 @@ void parse_fmt_sequence(struct fmt_sequence *sequence, const char **restrict pos static ssize_t render_c(const struct fmt_sequence *sequence, va_list *ap) { - ssize_t ret; - - if (sequence->length_modifier == LENGTH_L) { - wchar_t val = (wchar_t)va_arg(*ap, wint_t); - ret = printer->write(printer, &val, sizeof(val)); - } else { - char val = (char)va_arg(*ap, int); - ret = printer->write(printer, &val, sizeof(val)); - } + /* we don't support wchars until we have a UTF-8 encoder */ + if (sequence->length_modifier != LENGTH_DEFAULT) + return -1; - return ret; + char val = (char)va_arg(*ap, int); + return printer->write(printer, &val, sizeof(val)); } static ssize_t render_s(const struct fmt_sequence *sequence, va_list *ap) @@ -331,7 +326,13 @@ static ssize_t render_s(const struct fmt_sequence *sequence, va_list *ap) * the string is a wchar_t if LENGTH_L is set, but that would require * a full UTF-8 encoder which i won't write in the near future. Cope. */ + if (sequence->length_modifier != LENGTH_DEFAULT) + return -1; + const char *s = va_arg(*ap, char *); + if (s == nil) + return write_asciz("(null)"); + if (sequence->max_precision) return write_bytes(s, strnlen(s, sequence->max_precision)); else