* 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.
This commit is contained in:
parent
b889cfadf9
commit
d060ad60ee
2 changed files with 24 additions and 8 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2010-12-21 Colin Watson <cjwatson@ubuntu.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
2010-12-21 Colin Watson <cjwatson@ubuntu.com>
|
2010-12-21 Colin Watson <cjwatson@ubuntu.com>
|
||||||
|
|
||||||
* grub-core/fs/udf.c (read_string): Pacify GCC warning by
|
* grub-core/fs/udf.c (read_string): Pacify GCC warning by
|
||||||
|
|
|
@ -44,8 +44,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
{
|
{
|
||||||
char *arg = *args;
|
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++;
|
args++;
|
||||||
|
|
||||||
|
if (!unescaped)
|
||||||
|
return grub_errno;
|
||||||
|
|
||||||
while (*arg)
|
while (*arg)
|
||||||
{
|
{
|
||||||
/* In case `-e' is used, parse backslashes. */
|
/* In case `-e' is used, parse backslashes. */
|
||||||
|
@ -58,11 +64,11 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||||
switch (*arg)
|
switch (*arg)
|
||||||
{
|
{
|
||||||
case '\\':
|
case '\\':
|
||||||
grub_printf ("\\");
|
*p++ = '\\';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
grub_printf ("\a");
|
*p++ = '\a';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -70,23 +76,23 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
grub_printf ("\f");
|
*p++ = '\f';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
grub_printf ("\n");
|
*p++ = '\n';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
grub_printf ("\r");
|
*p++ = '\r';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
grub_printf ("\t");
|
*p++ = '\t';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
grub_printf ("\v");
|
*p++ = '\v';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
arg++;
|
arg++;
|
||||||
|
@ -95,10 +101,14 @@ grub_cmd_echo (grub_extcmd_context_t ctxt, int argc, char **args)
|
||||||
|
|
||||||
/* This was not an escaped character, or escaping is not
|
/* This was not an escaped character, or escaping is not
|
||||||
enabled. */
|
enabled. */
|
||||||
grub_printf ("%c", *arg);
|
*p++ = *arg;
|
||||||
arg++;
|
arg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*p = '\0';
|
||||||
|
grub_xputs (unescaped);
|
||||||
|
grub_free (unescaped);
|
||||||
|
|
||||||
/* If another argument follows, insert a space. */
|
/* If another argument follows, insert a space. */
|
||||||
if (i != argc - 1)
|
if (i != argc - 1)
|
||||||
grub_printf (" " );
|
grub_printf (" " );
|
||||||
|
|
Loading…
Reference in a new issue