cleanup & a fix

This commit is contained in:
BVK Chaitanya 2010-06-12 12:02:06 +05:30
parent 2f169df5a4
commit 0500dfd1b4
2 changed files with 27 additions and 22 deletions

View file

@ -154,18 +154,37 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate,
lexerstate->getline (&line, 1);
else
line = grub_strdup (input);
/* Ensure '\n' at the end. */
if (line && line[0] == '\0')
{
grub_free (line);
line = grub_strdup ("\n");
}
if (line && (len = grub_strlen(line)) && line[len - 1] != '\n')
{
p = grub_realloc (line, len + 2);
if (p)
{
p[len++] = '\n';
p[len] = '\0';
}
line = p;
}
if (! line)
{
grub_script_yyerror (parserstate, 0);
grub_script_yyerror (parserstate, "out of memory");
return 1;
}
len = grub_strlen (line);
/* Prepend any left over unput-text. */
if (lexerstate->prefix)
{
int plen = grub_strlen (lexerstate->prefix);
p = grub_malloc (len + plen + 2);
p = grub_malloc (len + plen + 1);
if (! p)
{
grub_free (line);
@ -174,31 +193,13 @@ grub_script_lexer_yywrap (struct grub_parser_param *parserstate,
grub_strcpy (p, lexerstate->prefix);
lexerstate->prefix = 0;
if (! line[0])
{
line = "\n";
len = 1;
}
grub_strcpy (p + plen, line);
grub_free (line);
line = p;
len = len + plen;
}
if (line[len - 1] != '\n')
{
char *p;
p = grub_realloc (line, len + 2);
if (! p)
{
grub_free (line);
return 1;
}
line = p;
line[len++] = '\n';
line[len] = '\0';
}
buffer = yy_scan_string (line, lexerstate->yyscanner);
grub_free (line);

View file

@ -60,3 +60,7 @@ echo one'two
echo one'two
\'three
# echo "one
#
# two"