Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp712imm; Tue, 17 Jul 2018 19:13:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcbdqfQ0o/mTYODfl40cp1vBhDGkgYPDGTzDQcBYI+Cu4swbHtcR+xY/Ta7zQ9XWEJr8lhS X-Received: by 2002:a65:5907:: with SMTP id f7-v6mr3814316pgu.83.1531879983515; Tue, 17 Jul 2018 19:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531879983; cv=none; d=google.com; s=arc-20160816; b=Q6ExAXW2IJGGpzrJ1S4F6KYa802HaCaKYhCWSyXGg1t5pz6RigJmb5J/vmZEzZryGX CVRDUvotFo1ZlVC/lM456XaLAe6VXGUk2IUKgo0eZ4hTirLzT9ExLa1muMY7GBY82//J gGFDkarK7MtUNKZIZAYKVSQaSLQnYKAoh0IpJ6C0Qn0tYWvCZs/kiY36o3nM/toH8Ekw BKDirf6O9jChraedYwwhoxs/91uwVM1X0z/wmaJ2Ke606Kw0qJ9f9X+PJyMj4YMW8F1j Z/SB0vtTMi8MI3W7qSKkxkODQ8cX5cFf+bwSbypZowJHw4N17dpi4WVM6fEWt4PGGbdH WPRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=dNnHHnr2cLUhB7QbQC3e7OzUOvd65yF2W/qUS2nQ+yQ=; b=HgzKUCAJ1rJgY4pxgyoQfM0V+RYqz7xuOHCzRXPZkodGIXg1C6kIkmD+MUD9sMOaQY x9hHd62hICye4lX5nQezXubqoKHZpvIgoBj9hv7zoXUSjejJBJMGGSiwQnYS0mMJD5EE MSPdd1ymMWW6hmT9fY/K7gNY84SACSYwDVeElOj+V5hb888cgPiwlG3nNbYSi10JVDhn u6QhBNIfIgFZCUMv7Q1Jv5CX9I43lTnjaTHrvNk5FVlf/hyv9an0d6uB5y+0D1/hQXYX T/j/Ald/0loFSlLCBmLhAmaJ/L86lfDbZIYzJeD3J92U6C5mxd6BFgIRKFOmP2W01+bR tELw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r5-v6si2133000pga.602.2018.07.17.19.12.48; Tue, 17 Jul 2018 19:13:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731422AbeGRCq0 (ORCPT + 99 others); Tue, 17 Jul 2018 22:46:26 -0400 Received: from tartarus.angband.pl ([89.206.35.136]:34244 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730930AbeGRCq0 (ORCPT ); Tue, 17 Jul 2018 22:46:26 -0400 Received: from 89-71-158-145.dynamic.chello.pl ([89.71.158.145] helo=umbar.angband.pl) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ffbvV-0007MC-Fd; Wed, 18 Jul 2018 04:10:52 +0200 Received: from kilobyte by umbar.angband.pl with local (Exim 4.91) (envelope-from ) id 1ffbvV-0008Uw-5c; Wed, 18 Jul 2018 04:10:49 +0200 From: Adam Borowski To: Greg Kroah-Hartman , Jiri Slaby , Nicolas Pitre , linux-kernel@vger.kernel.org, linux-console@vger.kernel.org Cc: Adam Borowski Date: Wed, 18 Jul 2018 04:10:43 +0200 Message-Id: <20180718021044.32611-2-kilobyte@angband.pl> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180718021044.32611-1-kilobyte@angband.pl> References: <20180718020604.3u25omf5fxqvsy3q@angband.pl> <20180718021044.32611-1-kilobyte@angband.pl> X-SA-Exim-Connect-IP: 89.71.158.145 X-SA-Exim-Mail-From: kilobyte@angband.pl X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tartarus X-Spam-Level: X-Spam-Status: No, score=-2.9 required=8.0 tests=ALL_TRUSTED=-1,BAYES_00=-1.9, TVD_RCVD_IP=0.001 autolearn=ham autolearn_force=no languages=en Subject: [PATCH 2/3] vt: selection: handle storing of characters above U+FFFF X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Those above U+10FFFF get replaced with U+FFFD. Signed-off-by: Adam Borowski --- drivers/tty/vt/selection.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c index 34e7110f310d..69ca337d3220 100644 --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -116,8 +116,8 @@ static inline int atedge(const int p, int size_row) return (!(p % size_row) || !((p + 2) % size_row)); } -/* stores the char in UTF8 and returns the number of bytes used (1-3) */ -static int store_utf8(u16 c, char *p) +/* stores the char in UTF8 and returns the number of bytes used (1-4) */ +static int store_utf8(u32 c, char *p) { if (c < 0x80) { /* 0******* */ @@ -128,13 +128,26 @@ static int store_utf8(u16 c, char *p) p[0] = 0xc0 | (c >> 6); p[1] = 0x80 | (c & 0x3f); return 2; - } else { + } else if (c < 0x10000) { /* 1110**** 10****** 10****** */ p[0] = 0xe0 | (c >> 12); p[1] = 0x80 | ((c >> 6) & 0x3f); p[2] = 0x80 | (c & 0x3f); return 3; - } + } else if (c < 0x110000) { + /* 11110*** 10****** 10****** 10****** */ + p[0] = 0xf0 | (c >> 18); + p[1] = 0x80 | ((c >> 12) & 0x3f); + p[2] = 0x80 | ((c >> 6) & 0x3f); + p[3] = 0x80 | (c & 0x3f); + return 4; + } else { + /* outside Unicode, replace with U+FFFD */ + p[0] = 0xef; + p[1] = 0xbf; + p[2] = 0xbd; + return 3; + } } /** @@ -273,7 +286,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t sel_end = new_sel_end; /* Allocate a new buffer before freeing the old one ... */ - multiplier = use_unicode ? 3 : 1; /* chars can take up to 3 bytes */ + multiplier = use_unicode ? 4 : 1; /* chars can take up to 4 bytes */ bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier, GFP_KERNEL); if (!bp) { -- 2.18.0