Fossil SCM
regexp.c (re_next_char): 3 off-by-one errors, and disallow characters > 0x10ffff unicode.c/diff.c: fix some gcc warnings
Commit
a13e0a20a8752b5c62a6c77c4b43a95c1162af19
Parent
c77995e6507331e…
3 files changed
+1
-2
+3
-3
+1
-1
+1
-2
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -423,11 +423,11 @@ | ||
| 423 | 423 | ReCompiled *pRe, /* The regular expression to be matched */ |
| 424 | 424 | DLine *aDLine, /* First of N DLines to compare against */ |
| 425 | 425 | int N /* Number of DLines to check */ |
| 426 | 426 | ){ |
| 427 | 427 | while( N-- ){ |
| 428 | - if( re_execute(pRe, aDLine->z, LENGTH(aDLine)) ){ | |
| 428 | + if( re_execute(pRe, (const unsigned char *)aDLine->z, LENGTH(aDLine)) ){ | |
| 429 | 429 | return 1; |
| 430 | 430 | } |
| 431 | 431 | aDLine++; |
| 432 | 432 | } |
| 433 | 433 | return 0; |
| @@ -1925,11 +1925,10 @@ | ||
| 1925 | 1925 | Blob *pOut, /* Write diff here if not NULL */ |
| 1926 | 1926 | ReCompiled *pRe, /* Only output changes where this Regexp matches */ |
| 1927 | 1927 | u64 diffFlags /* DIFF_* flags defined above */ |
| 1928 | 1928 | ){ |
| 1929 | 1929 | int ignoreEolWs; /* Ignore whitespace at the end of lines */ |
| 1930 | - int nContext; /* Amount of context to display */ | |
| 1931 | 1930 | DContext c; |
| 1932 | 1931 | |
| 1933 | 1932 | if( diffFlags & DIFF_INVERT ){ |
| 1934 | 1933 | Blob *pTemp = pA_Blob; |
| 1935 | 1934 | pA_Blob = pB_Blob; |
| 1936 | 1935 |
| --- 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 @@ | ||
| 134 | 134 | */ |
| 135 | 135 | static unsigned re_next_char(ReInput *p){ |
| 136 | 136 | unsigned c; |
| 137 | 137 | if( p->i>=p->mx ) return 0; |
| 138 | 138 | c = p->z[p->i++]; |
| 139 | - if( c>0x80 ){ | |
| 139 | + if( c>=0x80 ){ | |
| 140 | 140 | if( (c&0xe0)==0xc0 && p->i<p->mx && (p->z[p->i]&0xc0)==0x80 ){ |
| 141 | 141 | c = (c&0x1f)<<6 | (p->z[p->i++]&0x3f); |
| 142 | 142 | if( c<0x80 ) c = 0xfffd; |
| 143 | 143 | }else if( (c&0xf0)==0xe0 && p->i+1<p->mx && (p->z[p->i]&0xc0)==0x80 |
| 144 | 144 | && (p->z[p->i+1]&0xc0)==0x80 ){ |
| 145 | 145 | c = (c&0x0f)<<12 | ((p->z[p->i]&0x3f)<<6) | (p->z[p->i+1]&0x3f); |
| 146 | 146 | p->i += 2; |
| 147 | - if( c<0x3ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd; | |
| 147 | + if( c<=0x3ff || (c>=0xd800 && c<=0xdfff) ) c = 0xfffd; | |
| 148 | 148 | }else if( (c&0xf8)==0xf0 && p->i+3<p->mx && (p->z[p->i]&0xc0)==0x80 |
| 149 | 149 | && (p->z[p->i+1]&0xc0)==0x80 && (p->z[p->i+2]&0xc0)==0x80 ){ |
| 150 | 150 | c = (c&0x07)<<18 | ((p->z[p->i]&0x3f)<<12) | ((p->z[p->i+1]&0x3f)<<6) |
| 151 | 151 | | (p->z[p->i+2]&0x3f); |
| 152 | 152 | p->i += 3; |
| 153 | - if( c<0xffff ) c = 0xfffd; | |
| 153 | + if( c<=0xffff || c>0x10ffff ) c = 0xfffd; | |
| 154 | 154 | }else{ |
| 155 | 155 | c = 0xfffd; |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | return c; |
| 159 | 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 = 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 @@ | ||
| 131 | 131 | |
| 132 | 132 | if( c<128 ){ |
| 133 | 133 | return ( (aAscii[c >> 5] & (1 << (c & 0x001F)))==0 ); |
| 134 | 134 | }else if( c<(1<<22) ){ |
| 135 | 135 | unsigned int key = (((unsigned int)c)<<10) | 0x000003FF; |
| 136 | - int iRes; | |
| 136 | + int iRes = 0; | |
| 137 | 137 | int iHi = sizeof(aEntry)/sizeof(aEntry[0]) - 1; |
| 138 | 138 | int iLo = 0; |
| 139 | 139 | while( iHi>=iLo ){ |
| 140 | 140 | int iTest = (iHi + iLo) / 2; |
| 141 | 141 | if( key >= aEntry[iTest] ){ |
| 142 | 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; |
| 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 |