remove arbitrary limit on menuentry recording

This commit is contained in:
BVK Chaitanya 2010-01-23 00:42:55 +05:30
parent df6dc2113a
commit bae09d0d47
3 changed files with 15 additions and 10 deletions

View file

@ -172,8 +172,8 @@ struct grub_lexer_param
void *buffer; void *buffer;
}; };
#define GRUB_LEXER_INITIAL_TEXT_SIZE 32 #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. */ /* State of the parser as passes to the parser. */
struct grub_parser_param struct grub_parser_param

View file

@ -45,12 +45,11 @@ grub_script_lexer_record_start (struct grub_parser_param *parser)
lexer->record = 1; lexer->record = 1;
lexer->recordpos = 0; lexer->recordpos = 0;
if (lexer->recording) /* reuse last record */ if (lexer->recording) /* reuse last record */
return; return;
lexer->recordlen = GRUB_LEXER_RECORD_INCREMENT; lexer->recordlen = GRUB_LEXER_INITIAL_RECORD_SIZE;
lexer->recording = grub_malloc (lexer->recordlen); lexer->recording = grub_malloc (lexer->recordlen);
if (!lexer->recording) if (!lexer->recording)
{ {
grub_script_yyerror (parser, 0); grub_script_yyerror (parser, 0);
@ -99,27 +98,31 @@ grub_script_lexer_record_stop (struct grub_parser_param *parser)
return result; return result;
} }
#define MAX(a,b) ((a) < (b) ? (b) : (a))
/* Record STR if input recording is enabled. */ /* Record STR if input recording is enabled. */
void void
grub_script_lexer_record (struct grub_parser_param *parser, char *str) grub_script_lexer_record (struct grub_parser_param *parser, char *str)
{ {
int len; int len;
char *old;
struct grub_lexer_param *lexer = parser->lexerstate; struct grub_lexer_param *lexer = parser->lexerstate;
if (!lexer->record) if (!lexer->record)
return; return;
len = grub_strlen (str); len = grub_strlen (str);
if (lexer->recordpos + len >= lexer->recordlen - 1) if (lexer->recordpos + len + 1 > lexer->recordlen)
{ {
char *old = lexer->recording; old = lexer->recording;
lexer->recordlen += GRUB_LEXER_RECORD_INCREMENT; lexer->recordlen = MAX (len, lexer->recordlen) * 2;
lexer->recording = grub_realloc (lexer->recording, lexer->recordlen); lexer->recording = grub_realloc (lexer->recording, lexer->recordlen);
if (!lexer->recording) if (!lexer->recording)
{ {
grub_free (old); grub_free (old);
lexer->record = 0; lexer->record = 0;
lexer->recordpos = 0;
lexer->recordlen /= 2;
grub_script_yyerror (parser, 0); grub_script_yyerror (parser, 0);
return; return;
} }

View file

@ -315,16 +315,18 @@ grub_lexer_yyrealloc (void *ptr, yy_size_t size,
return grub_realloc (ptr, 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) static void copy_string (struct grub_parser_param *parser, const char *str, unsigned hint)
{ {
int len;
int size; int size;
char *ptr; char *ptr;
unsigned len;
len = hint ? hint : grub_strlen (str); len = hint ? hint : grub_strlen (str);
if (parser->lexerstate->used + len >= parser->lexerstate->size) 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); ptr = grub_realloc (parser->lexerstate->text, size);
if (!ptr) if (!ptr)
{ {