Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1PV1vV-0000w8-4c for mharc-grub-devel@gnu.org; Tue, 21 Dec 2010 08:06:49 -0500 Received: from [140.186.70.92] (port=58022 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PV1vR-0000tV-ID for grub-devel@gnu.org; Tue, 21 Dec 2010 08:06:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PV1vP-0000zr-KL for grub-devel@gnu.org; Tue, 21 Dec 2010 08:06:45 -0500 Received: from smarthost03.mail.zen.net.uk ([212.23.3.142]:42670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PV1vP-0000zF-Cr for grub-devel@gnu.org; Tue, 21 Dec 2010 08:06:43 -0500 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost03.mail.zen.net.uk with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1PV1vN-0001Rn-SE for grub-devel@gnu.org; Tue, 21 Dec 2010 13:06:42 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 4.69) (envelope-from ) id 1PV1vM-0006C3-Im for grub-devel@gnu.org; Tue, 21 Dec 2010 13:06:40 +0000 Date: Tue, 21 Dec 2010 13:06:39 +0000 From: Colin Watson To: grub-devel@gnu.org Message-ID: <20101221130639.GP21862@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost03-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] Make echo UTF-8-clean X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Dec 2010 13:06:47 -0000 While working on my previous patch, I noticed that echo wasn't UTF-8-clean: the UTF-8 character 'à' was coming out as "??". This patch fixes that. 2010-12-21 Colin Watson * grub-core/commands/echo.c (grub_cmd_echo): Make UTF-8-clean by constructing a new unescaped string and passing it to grub_xputs in one go, rather than passing characters to grub_printf one at a time. === modified file 'grub-core/commands/echo.c' --- grub-core/commands/echo.c 2010-11-30 15:23:41 +0000 +++ grub-core/commands/echo.c 2010-12-21 13:03:09 +0000 @@ -44,6 +44,9 @@ grub_cmd_echo (grub_extcmd_context_t ctx for (i = 0; i < argc; i++) { char *arg = *args; + /* Unescaping results in a string no longer than the original. */ + char *unescaped = grub_malloc (grub_strlen (arg) + 1); + char *p = unescaped; args++; while (*arg) @@ -58,11 +61,11 @@ grub_cmd_echo (grub_extcmd_context_t ctx switch (*arg) { case '\\': - grub_printf ("\\"); + *p++ = '\\'; break; case 'a': - grub_printf ("\a"); + *p++ = '\a'; break; case 'c': @@ -70,23 +73,23 @@ grub_cmd_echo (grub_extcmd_context_t ctx break; case 'f': - grub_printf ("\f"); + *p++ = '\f'; break; case 'n': - grub_printf ("\n"); + *p++ = '\n'; break; case 'r': - grub_printf ("\r"); + *p++ = '\r'; break; case 't': - grub_printf ("\t"); + *p++ = '\t'; break; case 'v': - grub_printf ("\v"); + *p++ = '\v'; break; } arg++; @@ -95,10 +98,14 @@ grub_cmd_echo (grub_extcmd_context_t ctx /* This was not an escaped character, or escaping is not enabled. */ - grub_printf ("%c", *arg); + *p++ = *arg; arg++; } + *p = '\0'; + grub_xputs (unescaped); + grub_free (unescaped); + /* If another argument follows, insert a space. */ if (i != argc - 1) grub_printf (" " ); -- Colin Watson [cjwatson@ubuntu.com]