@@ -79,8 +79,7 @@ static void vuart_print_char(struct vcpu *v, char c)
struct domain *d = v->domain;
struct vuart *uart = &d->arch.vuart;
- /* Accept only printable characters, newline, and horizontal tab. */
- if ( !isprint(c) && (c != '\n') && (c != '\t') )
+ if ( !is_console_printable(c) )
return ;
spin_lock(&uart->lock);
@@ -561,8 +561,7 @@ static int cf_check hvm_print_line(
if ( dir != IOREQ_WRITE )
return X86EMUL_UNHANDLEABLE;
- /* Accept only printable characters, newline, and horizontal tab. */
- if ( !isprint(c) && (c != '\n') && (c != '\t') )
+ if ( !is_console_printable(c) )
return X86EMUL_OKAY;
spin_lock(&cd->pbuf_lock);
@@ -674,7 +674,7 @@ static long guest_console_write(XEN_GUEST_HANDLE_PARAM(char) buffer,
c = *kin++;
if ( c == '\n' )
break;
- if ( isprint(c) || c == '\t' )
+ if ( is_console_printable(c) )
*kout++ = c;
} while ( --kcount > 0 );
@@ -4,6 +4,8 @@
/*
* NOTE! This ctype does not handle EOF like the standard C
* library is required to.
+ *
+ * See Rule 21.13 in docs/misra/rules.rst.
*/
#define _U 0x01 /* upper */
@@ -51,4 +53,9 @@ static inline unsigned char __toupper(unsigned char c)
#define tolower(c) ((char)__tolower(c))
#define toupper(c) ((char)__toupper(c))
+static inline unsigned is_console_printable(unsigned char c)
+{
+ return isprint(c) || c == '\n' || c == '\t';
+}
+
#endif