aboutsummaryrefslogtreecommitdiffhomepage
path: root/parser.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-01-12 22:54:57 +1000
committerGravatar axel <axel@liljencrantz.se>2006-01-12 22:54:57 +1000
commit10fec8abb609cf2d554de89584089917019980ad (patch)
tree14e7f7c39baf1aabf119bf01dae0b742f5e9c0cb /parser.c
parentda058aa141d4d96cec24f439357c3d23242c7528 (diff)
Make parser_current_line use dynamic memory to avoid overflow on long lines
darcs-hash:20060112125457-ac50b-1eff13f647793701e620a675ff661bc7d823a843.gz
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/parser.c b/parser.c
index c46e8a48..f1b72f05 100644
--- a/parser.c
+++ b/parser.c
@@ -37,9 +37,6 @@ The fish parser. Contains functions for parsing code.
#include "event.h"
#include "translate.h"
-/** Length of the lineinfo string used for describing the current tokenizer position */
-#define LINEINFO_SIZE 128
-
/**
Maximum number of block levels in code. This is not the same as
maximum recursion depth, this only has to do with how many block
@@ -253,7 +250,7 @@ static wchar_t err_str[256];
static tokenizer *current_tokenizer;
/** String for representing the current line */
-static wchar_t lineinfo[LINEINFO_SIZE];
+static string_buffer_t *lineinfo=0;
/** This is the position of the beginning of the currently parsed command */
static int current_tokenizer_pos;
@@ -998,12 +995,17 @@ wchar_t *parser_current_line()
int i;
int offset;
int current_line_pos=current_tokenizer_pos;
-
+
if( !line )
return L"";
- lineinfo[0]=0;
-
+ if( !lineinfo )
+ {
+ lineinfo = malloc( sizeof(string_buffer_t) );
+ sb_init( lineinfo );
+ }
+ sb_clear( lineinfo );
+
/*
Calculate line number, line offset, etc.
*/
@@ -1026,16 +1028,15 @@ wchar_t *parser_current_line()
line = wcsndup( line, line_end-line );
- debug( 4, L"Current pos %d, line pos %d, file_length %d\n", current_tokenizer_pos, current_line_pos, wcslen(whole_str));
+ debug( 4, L"Current pos %d, line pos %d, file_length %d, is_interactive %d\n", current_tokenizer_pos, current_line_pos, wcslen(whole_str), is_interactive);
if( !is_interactive )
{
- swprintf( lineinfo,
- LINEINFO_SIZE,
- _(L"%ls (line %d): %n"),
- file,
- lineno,
- &offset );
+ sb_printf( lineinfo,
+ _(L"%ls (line %d): "),
+ file,
+ lineno );
+ offset = my_wcswidth( (wchar_t *)lineinfo->buff );
}
else
{
@@ -1046,17 +1047,17 @@ wchar_t *parser_current_line()
Skip printing character position if we are in interactive mode
and the error was on the first character of the line
*/
- if( offset+current_line_pos )
- swprintf( lineinfo+offset,
- LINEINFO_SIZE-offset,
- L"%ls\n%*c^\n",
- line,
- offset+current_line_pos,
- L' ' );
-
+ if( !is_interactive || (current_line_pos!=0) )
+ {
+ sb_printf( lineinfo,
+ L"%ls\n%*c^\n",
+ line,
+ offset+current_line_pos,
+ L' ' );
+ }
free( line );
- return lineinfo;
+ return (wchar_t *)lineinfo->buff;
}
int parser_get_pos()