For for crash when typing backslash c

This commit is contained in:
ridiculousfish 2012-03-03 20:38:16 -08:00
parent a0bb2cdc6e
commit 5ae77b4317
2 changed files with 39 additions and 39 deletions

View file

@ -242,15 +242,15 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
int normal_status = colors.at(0); int normal_status = colors.at(0);
for( in_pos=0; for( in_pos=0;
in_pos<len; in_pos<len;
in_pos++ ) in_pos++ )
{ {
wchar_t c = buffstr.at(in_pos); wchar_t c = buffstr.at(in_pos);
switch( mode ) switch( mode )
{ {
/* /*
Mode 0 means unquoted string Mode 0 means unquoted string
*/ */
case 0: case 0:
{ {
if( c == L'\\' ) if( c == L'\\' )
@ -280,9 +280,10 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos+1)=normal_status; colors.at(in_pos+1)=normal_status;
} }
else if( wcschr( L"c", buff[in_pos] ) ) else if( wcschr( L"c", buff[in_pos] ) )
{ {
colors.at(start_pos)=HIGHLIGHT_ESCAPE; colors.at(start_pos)=HIGHLIGHT_ESCAPE;
colors.at(in_pos+2)=normal_status; if (in_pos+2 < colors.size())
colors.at(in_pos+2)=normal_status;
} }
else if( wcschr( L"uUxX01234567", buff[in_pos] ) ) else if( wcschr( L"uUxX01234567", buff[in_pos] ) )
{ {
@ -302,26 +303,26 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
max_val = UCS2_MAX; max_val = UCS2_MAX;
break; break;
} }
case L'U': case L'U':
{ {
chars=8; chars=8;
max_val = WCHAR_MAX; max_val = WCHAR_MAX;
break; break;
} }
case L'x': case L'x':
{ {
break; break;
} }
case L'X': case L'X':
{ {
byte=1; byte=1;
max_val = BYTE_MAX; max_val = BYTE_MAX;
break; break;
} }
default: default:
{ {
base=8; base=8;
@ -343,7 +344,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
res=(res*base)|d; res=(res*base)|d;
} }
if( (res <= max_val) ) if( (res <= max_val) )
{ {
colors.at(start_pos) = HIGHLIGHT_ESCAPE; colors.at(start_pos) = HIGHLIGHT_ESCAPE;
@ -355,7 +356,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos+1) = normal_status; colors.at(in_pos+1) = normal_status;
} }
} }
} }
else else
{ {
@ -370,7 +371,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
} }
break; break;
} }
case L'$': case L'$':
{ {
wchar_t n = buff[in_pos+1]; wchar_t n = buff[in_pos+1];
@ -378,8 +379,8 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos+1) = normal_status; colors.at(in_pos+1) = normal_status;
break; break;
} }
case L'*': case L'*':
case L'?': case L'?':
case L'(': case L'(':
@ -389,7 +390,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos+1) = normal_status; colors.at(in_pos+1) = normal_status;
break; break;
} }
case L'{': case L'{':
{ {
colors.at(in_pos) = HIGHLIGHT_OPERATOR; colors.at(in_pos) = HIGHLIGHT_OPERATOR;
@ -397,7 +398,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
bracket_count++; bracket_count++;
break; break;
} }
case L'}': case L'}':
{ {
colors.at(in_pos) = HIGHLIGHT_OPERATOR; colors.at(in_pos) = HIGHLIGHT_OPERATOR;
@ -405,7 +406,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
bracket_count--; bracket_count--;
break; break;
} }
case L',': case L',':
{ {
if( bracket_count ) if( bracket_count )
@ -413,32 +414,32 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos) = HIGHLIGHT_OPERATOR; colors.at(in_pos) = HIGHLIGHT_OPERATOR;
colors.at(in_pos+1) = normal_status; colors.at(in_pos+1) = normal_status;
} }
break; break;
} }
case L'\'': case L'\'':
{ {
colors.at(in_pos) = HIGHLIGHT_QUOTE; colors.at(in_pos) = HIGHLIGHT_QUOTE;
mode = 1; mode = 1;
break; break;
} }
case L'\"': case L'\"':
{ {
colors.at(in_pos) = HIGHLIGHT_QUOTE; colors.at(in_pos) = HIGHLIGHT_QUOTE;
mode = 2; mode = 2;
break; break;
} }
} }
} }
break; break;
} }
/* /*
Mode 1 means single quoted string, i.e 'foo' Mode 1 means single quoted string, i.e 'foo'
*/ */
case 1: case 1:
{ {
if( c == L'\\' ) if( c == L'\\' )
@ -453,12 +454,12 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos+1) = HIGHLIGHT_QUOTE; colors.at(in_pos+1) = HIGHLIGHT_QUOTE;
break; break;
} }
case 0: case 0:
{ {
return; return;
} }
} }
} }
@ -470,10 +471,10 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
break; break;
} }
/* /*
Mode 2 means double quoted string, i.e. "foo" Mode 2 means double quoted string, i.e. "foo"
*/ */
case 2: case 2:
{ {
switch( c ) switch( c )
@ -484,7 +485,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos+1) = normal_status; colors.at(in_pos+1) = normal_status;
break; break;
} }
case '\\': case '\\':
{ {
int start_pos = in_pos; int start_pos = in_pos;
@ -494,7 +495,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
{ {
return; return;
} }
case '\\': case '\\':
case L'$': case L'$':
case '"': case '"':
@ -506,7 +507,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
} }
break; break;
} }
case '$': case '$':
{ {
wchar_t n = buff[in_pos+1]; wchar_t n = buff[in_pos+1];
@ -514,7 +515,7 @@ static void highlight_param( const wcstring &buffstr, std::vector<int> &colors,
colors.at(in_pos+1) = HIGHLIGHT_QUOTE; colors.at(in_pos+1) = HIGHLIGHT_QUOTE;
break; break;
} }
} }
break; break;
} }

View file

@ -429,8 +429,7 @@ static wint_t input_try_mapping( const input_mapping_t &m)
input_unreadch( c ); input_unreadch( c );
const wchar_t *str = m.seq.c_str(); const wchar_t *str = m.seq.c_str();
for( j=0; str[j] != L'\0' && for( j=0; str[j] != L'\0' && str[j] == (c=input_common_readch( j>0 )); j++ )
str[j] == (c=input_common_readch( j>0 )); j++ )
; ;
if( str[j] == L'\0' ) if( str[j] == L'\0' )