remove arbitrary limit on menuentry recording
This commit is contained in:
parent
df6dc2113a
commit
bae09d0d47
3 changed files with 15 additions and 10 deletions
|
@ -173,7 +173,7 @@ struct grub_lexer_param
|
|||
};
|
||||
|
||||
#define GRUB_LEXER_INITIAL_TEXT_SIZE 32
|
||||
#define GRUB_LEXER_RECORD_INCREMENT 256
|
||||
#define GRUB_LEXER_INITIAL_RECORD_SIZE 256
|
||||
|
||||
/* State of the parser as passes to the parser. */
|
||||
struct grub_parser_param
|
||||
|
|
|
@ -48,9 +48,8 @@ grub_script_lexer_record_start (struct grub_parser_param *parser)
|
|||
if (lexer->recording) /* reuse last record */
|
||||
return;
|
||||
|
||||
lexer->recordlen = GRUB_LEXER_RECORD_INCREMENT;
|
||||
lexer->recordlen = GRUB_LEXER_INITIAL_RECORD_SIZE;
|
||||
lexer->recording = grub_malloc (lexer->recordlen);
|
||||
|
||||
if (!lexer->recording)
|
||||
{
|
||||
grub_script_yyerror (parser, 0);
|
||||
|
@ -99,27 +98,31 @@ grub_script_lexer_record_stop (struct grub_parser_param *parser)
|
|||
return result;
|
||||
}
|
||||
|
||||
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
|
||||
/* Record STR if input recording is enabled. */
|
||||
void
|
||||
grub_script_lexer_record (struct grub_parser_param *parser, char *str)
|
||||
{
|
||||
int len;
|
||||
char *old;
|
||||
struct grub_lexer_param *lexer = parser->lexerstate;
|
||||
|
||||
if (!lexer->record)
|
||||
return;
|
||||
|
||||
len = grub_strlen (str);
|
||||
if (lexer->recordpos + len >= lexer->recordlen - 1)
|
||||
if (lexer->recordpos + len + 1 > lexer->recordlen)
|
||||
{
|
||||
char *old = lexer->recording;
|
||||
lexer->recordlen += GRUB_LEXER_RECORD_INCREMENT;
|
||||
old = lexer->recording;
|
||||
lexer->recordlen = MAX (len, lexer->recordlen) * 2;
|
||||
lexer->recording = grub_realloc (lexer->recording, lexer->recordlen);
|
||||
if (!lexer->recording)
|
||||
{
|
||||
grub_free (old);
|
||||
lexer->record = 0;
|
||||
lexer->recordpos = 0;
|
||||
lexer->recordlen /= 2;
|
||||
grub_script_yyerror (parser, 0);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -315,16 +315,18 @@ grub_lexer_yyrealloc (void *ptr, yy_size_t size,
|
|||
return grub_realloc (ptr, size);
|
||||
}
|
||||
|
||||
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
|
||||
static void copy_string (struct grub_parser_param *parser, const char *str, unsigned hint)
|
||||
{
|
||||
int len;
|
||||
int size;
|
||||
char *ptr;
|
||||
unsigned len;
|
||||
|
||||
len = hint ? hint : grub_strlen (str);
|
||||
if (parser->lexerstate->used + len >= parser->lexerstate->size)
|
||||
{
|
||||
size = parser->lexerstate->size * 2;
|
||||
size = MAX (len, parser->lexerstate->size) * 2;
|
||||
ptr = grub_realloc (parser->lexerstate->text, size);
|
||||
if (!ptr)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue