Fossil SCM

regexp.c (re_next_char): 3 off-by-one errors, and disallow characters > 0x10ffff unicode.c/diff.c: fix some gcc warnings

jan.nijtmans 2013-01-03 13:38 trunk
Commit a13e0a20a8752b5c62a6c77c4b43a95c1162af19
3 files changed +1 -2 +3 -3 +1 -1
+1 -2
--- src/diff.c
+++ src/diff.c
@@ -423,11 +423,11 @@
423423
ReCompiled *pRe, /* The regular expression to be matched */
424424
DLine *aDLine, /* First of N DLines to compare against */
425425
int N /* Number of DLines to check */
426426
){
427427
while( N-- ){
428
- if( re_execute(pRe, aDLine->z, LENGTH(aDLine)) ){
428
+ if( re_execute(pRe, (const unsigned char *)aDLine->z, LENGTH(aDLine)) ){
429429
return 1;
430430
}
431431
aDLine++;
432432
}
433433
return 0;
@@ -1925,11 +1925,10 @@
19251925
Blob *pOut, /* Write diff here if not NULL */
19261926
ReCompiled *pRe, /* Only output changes where this Regexp matches */
19271927
u64 diffFlags /* DIFF_* flags defined above */
19281928
){
19291929
int ignoreEolWs; /* Ignore whitespace at the end of lines */
1930
- int nContext; /* Amount of context to display */
19311930
DContext c;
19321931
19331932
if( diffFlags & DIFF_INVERT ){
19341933
Blob *pTemp = pA_Blob;
19351934
pA_Blob = pB_Blob;
19361935
--- src/diff.c
+++ src/diff.c
@@ -423,11 +423,11 @@
423 ReCompiled *pRe, /* The regular expression to be matched */
424 DLine *aDLine, /* First of N DLines to compare against */
425 int N /* Number of DLines to check */
426 ){
427 while( N-- ){
428 if( re_execute(pRe, aDLine->z, LENGTH(aDLine)) ){
429 return 1;
430 }
431 aDLine++;
432 }
433 return 0;
@@ -1925,11 +1925,10 @@
1925 Blob *pOut, /* Write diff here if not NULL */
1926 ReCompiled *pRe, /* Only output changes where this Regexp matches */
1927 u64 diffFlags /* DIFF_* flags defined above */
1928 ){
1929 int ignoreEolWs; /* Ignore whitespace at the end of lines */
1930 int nContext; /* Amount of context to display */
1931 DContext c;
1932
1933 if( diffFlags & DIFF_INVERT ){
1934 Blob *pTemp = pA_Blob;
1935 pA_Blob = pB_Blob;
1936
--- src/diff.c
+++ src/diff.c
@@ -423,11 +423,11 @@
423 ReCompiled *pRe, /* The regular expression to be matched */
424 DLine *aDLine, /* First of N DLines to compare against */
425 int N /* Number of DLines to check */
426 ){
427 while( N-- ){
428 if( re_execute(pRe, (const unsigned char *)aDLine->z, LENGTH(aDLine)) ){
429 return 1;
430 }
431 aDLine++;
432 }
433 return 0;
@@ -1925,11 +1925,10 @@
1925 Blob *pOut, /* Write diff here if not NULL */
1926 ReCompiled *pRe, /* Only output changes where this Regexp matches */
1927 u64 diffFlags /* DIFF_* flags defined above */
1928 ){
1929 int ignoreEolWs; /* Ignore whitespace at the end of lines */
 
1930 DContext c;
1931
1932 if( diffFlags & DIFF_INVERT ){
1933 Blob *pTemp = pA_Blob;
1934 pA_Blob = pB_Blob;
1935
+3 -3
--- src/regexp.c
+++ src/regexp.c
@@ -134,25 +134,25 @@
134134
*/
135135
static unsigned re_next_char(ReInput *p){
136136
unsigned c;
137137
if( p->i>=p->mx ) return 0;
138138
c = p->z[p->i++];
139
- if( c>0x80 ){
139
+ if( c>=0x80 ){
140140
if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){
141141
c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f);
142142
if( c<0x80 ) c = 0xfffd;
143143
}else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80
144144
&& (p->z[p->i+1]&0xc0)==0x80 ){
145145
c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f);
146146
p->i += 2;
147
- if( c<0x3ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd;
147
+ if( c<=0x3ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd;
148148
}else if( (c&0xf8)==0xf0 && p->i+3<p->mx && (p->z[p->i]&0xc0)==0x80
149149
&& (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){
150150
c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6)
151151
| (p->z[p->i+2]&0x3f);
152152
p->i += 3;
153
- if( c<0xffff ) c = 0xfffd;
153
+ if( c<=0xffff || c>0x10ffff ) c = 0xfffd;
154154
}else{
155155
c = 0xfffd;
156156
}
157157
}
158158
return c;
159159
--- src/regexp.c
+++ src/regexp.c
@@ -134,25 +134,25 @@
134 */
135 static unsigned re_next_char(ReInput *p){
136 unsigned c;
137 if( p->i>=p->mx ) return 0;
138 c = p->z[p->i++];
139 if( c>0x80 ){
140 if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){
141 c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f);
142 if( c<0x80 ) c = 0xfffd;
143 }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80
144 && (p->z[p->i+1]&0xc0)==0x80 ){
145 c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f);
146 p->i += 2;
147 if( c<0x3ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd;
148 }else if( (c&0xf8)==0xf0 && p->i+3<p->mx && (p->z[p->i]&0xc0)==0x80
149 && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){
150 c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6)
151 | (p->z[p->i+2]&0x3f);
152 p->i += 3;
153 if( c<0xffff ) c = 0xfffd;
154 }else{
155 c = 0xfffd;
156 }
157 }
158 return c;
159
--- src/regexp.c
+++ src/regexp.c
@@ -134,25 +134,25 @@
134 */
135 static unsigned re_next_char(ReInput *p){
136 unsigned c;
137 if( p->i>=p->mx ) return 0;
138 c = p->z[p->i++];
139 if( c>=0x80 ){
140 if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){
141 c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f);
142 if( c<0x80 ) c = 0xfffd;
143 }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80
144 && (p->z[p->i+1]&0xc0)==0x80 ){
145 c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f);
146 p->i += 2;
147 if( c<=0x3ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd;
148 }else if( (c&0xf8)==0xf0 && p->i+3<p->mx && (p->z[p->i]&0xc0)==0x80
149 && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){
150 c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6)
151 | (p->z[p->i+2]&0x3f);
152 p->i += 3;
153 if( c<=0xffff || c>0x10ffff ) c = 0xfffd;
154 }else{
155 c = 0xfffd;
156 }
157 }
158 return c;
159
+1 -1
--- src/unicode.c
+++ src/unicode.c
@@ -131,11 +131,11 @@
131131
132132
if( c<128 ){
133133
return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 );
134134
}else if( c<(1<<22) ){
135135
unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
136
- int iRes;
136
+ int iRes = 0;
137137
int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
138138
int iLo = 0;
139139
while( iHi>=iLo ){
140140
int iTest = (iHi + iLo) / 2;
141141
if( key >= aEntry[iTest] ){
142142
--- src/unicode.c
+++ src/unicode.c
@@ -131,11 +131,11 @@
131
132 if( c<128 ){
133 return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 );
134 }else if( c<(1<<22) ){
135 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
136 int iRes;
137 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
138 int iLo = 0;
139 while( iHi>=iLo ){
140 int iTest = (iHi + iLo) / 2;
141 if( key >= aEntry[iTest] ){
142
--- src/unicode.c
+++ src/unicode.c
@@ -131,11 +131,11 @@
131
132 if( c<128 ){
133 return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 );
134 }else if( c<(1<<22) ){
135 unsigned int key = (((unsigned int)c)<<10) | 0x000003FF;
136 int iRes = 0;
137 int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1;
138 int iLo = 0;
139 while( iHi>=iLo ){
140 int iTest = (iHi + iLo) / 2;
141 if( key >= aEntry[iTest] ){
142

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button