aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.c
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-24 22:18:29 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-24 22:18:29 +1000
commit1075ca69b0ef393b78952c0de639252fb70d559d (patch)
tree3a39e680d379361071bfb25559d817d271251eaf /common.c
parente29f5c5474ab59a2487cd5216810b090cd2b13f6 (diff)
Switch to standard syntax for octal escapes
darcs-hash:20060224121829-ac50b-8e19f27857378e6456ae08269721138bd60f3464.gz
Diffstat (limited to 'common.c')
-rw-r--r--common.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/common.c b/common.c
index d1d2fe21..76da6eba 100644
--- a/common.c
+++ b/common.c
@@ -917,74 +917,87 @@ wchar_t *unescape( const wchar_t * orig, int unescape_special )
break;
}
- case L'X':
case L'u':
case L'U':
case L'x':
- case L'o':
+ case L'X':
+ case L'0':
+ case L'1':
+ case L'2':
+ case L'3':
+ case L'4':
+ case L'5':
+ case L'6':
+ case L'7':
{
int i;
- wchar_t res=0;
+ long long res=0;
int chars=2;
int base=16;
int byte = 0;
+ int max_val = 127;
switch( in[in_pos] )
{
case L'u':
{
- base=16;
chars=4;
+ max_val = 35535;
break;
}
case L'U':
{
- base=16;
chars=8;
+ max_val = WCHAR_MAX;
break;
}
case L'x':
{
- base=16;
- chars=2;
break;
}
case L'X':
{
byte=1;
- base=16;
- chars=2;
+ max_val = 255;
break;
}
- case L'o':
+ default:
{
base=8;
chars=3;
+ in_pos--;
break;
- }
-
+ }
}
for( i=0; i<chars; i++ )
{
int d = convert_digit( in[++in_pos],base);
+
if( d < 0 )
{
in_pos--;
break;
}
-
+
res=(res*base)|d;
-
}
-
- in[out_pos] = (byte?ENCODE_DIRECT_BASE:0)+res;
-
+
+ if( (res > 0) && (res <= max_val) )
+ {
+ in[out_pos] = (byte?ENCODE_DIRECT_BASE:0)+res;
+ }
+ else
+ {
+ free(in);
+ return 0;
+ }
+
break;
}